﻿using BonjourQuotation.ObjectModel.AccountData;
using BonjourQuotation.ObjectModel.BusinessData;
using BonjourQuotation.ObjectModel.LoggerData;
using BonjourQuotation.UI.Models;
using BonjourQuotation.UI.Models.AccountModel;
using BonjourQuotation.UI.Models.PartialModel;
using BonjourQuotation.UI.Models.Shared;
using BonjourQuotation.UI.Models.ReportModel;
using BonjourQuotation.UI.ServiceManagers;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;


namespace BonjourQuotation.UI.Controllers
{
    public class OperationController : BaseController
    {
        OperationManager OprManager;
        private readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        // 
        [Authorize]
        public ActionResult Operation()
        {
            OperationViewModel OperViewModel = new OperationViewModel();
            this.SetPermission(OperViewModel, AllPermVModel);
            return View(OperViewModel);
        }
        
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationRooms(OperationRoomGridViewModel model)
        {
            if (model.RoomPageNumber == 0)
            {
                ResetAllRoomsProp(model);
                OperationRoomGridViewModel OperRoomGridView = new OperationRoomGridViewModel();
                OperRoomGridView.RoomFilterCustomer = new List<CheckBoxControlViewModel>();
                OperRoomGridView.RoomFilterRoomTitle = new List<CheckBoxControlViewModel>();
                OperRoomGridView.RoomFilterRoomType = new List<CheckBoxControlViewModel>();
                OperRoomGridView.Rows = new List<OperationRoomGridRowViewModel>();
                OperationRoomInitModelState(OperRoomGridView, model);
                return PartialView("OperationRoomGrid", OperRoomGridView);
            }
            var OperRoomVModel = LoadOperationRoomGridDatainit(model);
            this.SetPermission(OperRoomVModel, AllPermVModel);
            return PartialView("OperationRoomGrid", OperRoomVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationHotels(OperationHotelGridViewModel model)
        {
            if (model.HotelPageNumber == 0)
                ResetAllHotelProp(model);

            var OperHotelVModel = LoadOperationHotelGridDatainit(model);

            this.SetPermission(OperHotelVModel, AllPermVModel);
            if (model.HotelPageNumber > 1)
            {
                OperHotelVModel.IsCanPrev = true;
            }
            else
            {
                OperHotelVModel.IsCanPrev = false;
            }
            if (model.HotelPageNumber < OperHotelVModel.CountCheck)
            {
                OperHotelVModel.IsCanNext = true;
            }
            else
            {
                OperHotelVModel.IsCanNext = false;
            }
            return PartialView("OperationHotelGrid", OperHotelVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationHotelGridData(OperationHotelGridViewModel model)
        {
            ModelState.Clear();
            if (model.IsSearch || model.IsView)
            {
                var OperHotelVModel = SearchOperationHotelGridDatainit(model);
                this.SetPermission(OperHotelVModel, AllPermVModel);
                if (model.HotelPageNumber > 1)
                {
                    OperHotelVModel.IsCanPrev = true;
                }
                else
                {
                    OperHotelVModel.IsCanPrev = false;
                }
                if (model.HotelPageNumber < OperHotelVModel.CountCheck)
                {
                    OperHotelVModel.IsCanNext = true;
                }
                else
                {
                    OperHotelVModel.IsCanNext = false;
                }
                return PartialView("OperationHotelGrid", OperHotelVModel);
            }
            if (model.IsFilter)
            {
                var OperHotelVModel =  OperationHotelGridFilterDatainit(model);
                this.SetPermission(OperHotelVModel, AllPermVModel);
                if (model.HotelPageNumber > 1)
                {
                    OperHotelVModel.IsCanPrev = true;
                }
                else
                {
                    OperHotelVModel.IsCanPrev = false;
                }
                if (model.HotelPageNumber < OperHotelVModel.CountCheck)
                {
                    OperHotelVModel.IsCanNext = true;
                }
                else
                {
                    OperHotelVModel.IsCanNext = false;
                }
                return PartialView("OperationHotelGrid", OperHotelVModel);
            }
            return PartialView();
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationHotelGridSaveData(OperationHotelGridViewModel model)
        {
            var OperHotelVModel = OperationHotelGridSaveDatainit(model);
            this.SetPermission(OperHotelVModel, AllPermVModel);
            if (model.HotelPageNumber > 1)
            {
                OperHotelVModel.IsCanPrev = true;
            }
            else
            {
                OperHotelVModel.IsCanPrev = false;

            }
            if (model.HotelPageNumber < OperHotelVModel.CountCheck)
            {
                OperHotelVModel.IsCanNext = true;
            }
            else
            {
                OperHotelVModel.IsCanNext = false;
            }
            return PartialView("OperationHotelGrid", OperHotelVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationRoomGridData(OperationRoomGridViewModel model)
        {
            ModelState.Clear();
            if (model.IsRoomView)
            {
                this.SetPermission(model, AllPermVModel);
                return LoadOperationRooms(model);
            }
            if (model.IsRoomSearch)
            {
                var OperRoomVModel = SearchOperationRoomGridDatainit(model);
                this.SetPermission(OperRoomVModel, AllPermVModel);
                return PartialView("OperationRoomGrid", OperRoomVModel);
            }
            if (model.IsRoomFilter)
            {
                var OperRoomVModel = OperationRoomGridFilterDatainit(model);
                this.SetPermission(OperRoomVModel, AllPermVModel);
                return PartialView("OperationRoomGrid", OperRoomVModel);
            }
            if (model.IsRoomRemove)
            {
                var OperRoomVModel = OperationRoomGridRemoveDatainit(model);
                this.SetPermission(OperRoomVModel, AllPermVModel);
                return PartialView("OperationRoomGrid", OperRoomVModel);
            }

            var OperRoomVModelGlobal = OperationRoomGridSaveDatainit(model);
            this.SetPermission(OperRoomVModelGlobal, AllPermVModel);
            return PartialView("OperationRoomGrid", OperRoomVModelGlobal);
        }
        [Authorize]
        [HttpPost]
        public JsonResult OperationRoomGridOverwriteAll(int GroupID)
        {
            OprManager = new OperationManager();
            var ErrorMessage = OprManager.OverWriteOperationRooms(Convert.ToInt32(GroupID));
            return this.Json(ErrorMessage);
        }
        [Authorize]
        [HttpPost]
        public JsonResult OperationRoomGridOverwrite(int GroupID, int VendorID, DateTime ArrivalDate)
        {
            OprManager = new OperationManager();
            var ErrorMessage = OprManager.OverWriteOperationRoomsByVendorID(GroupID, VendorID, ArrivalDate);
            return this.Json(ErrorMessage);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationHotelByGroup(string GroupCode)
        {
            OprManager = new OperationManager();
            OperationHotelGridViewModel HotelModel = new OperationHotelGridViewModel();
            ResetAllHotelProp(HotelModel);
            if (OprManager.CheckGroupCodeRegion(GroupCode, UserRegions))
                HotelModel.SearchGroupCode = GroupCode;
            var OperHotelVModel = SearchOperationHotelGridDatainit(HotelModel);
            this.SetPermission(OperHotelVModel, AllPermVModel);
            if (OperHotelVModel.HotelPageNumber > 1)
            {
                OperHotelVModel.IsCanPrev = true;
            }
            else
            {
                OperHotelVModel.IsCanPrev = false;
            }
            if (OperHotelVModel.HotelPageNumber < OperHotelVModel.CountCheck)
            {
                OperHotelVModel.IsCanNext = true;
            }
            else
            {
                OperHotelVModel.IsCanNext = false;
            }
            return PartialView("OperationHotelGrid", OperHotelVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationRoomByGroup(string GroupCode)
        {
            OprManager = new OperationManager();
            OperationRoomGridViewModel RoomModel = new OperationRoomGridViewModel();
            if (OprManager.CheckGroupCodeRegion(GroupCode, UserRegions))
                RoomModel.RoomGroupCodeTxt = GroupCode;
            var OperRoomVModel = SearchOperationRoomGridDatainit(RoomModel);
            this.SetPermission(OperRoomVModel, AllPermVModel);
            return PartialView("OperationRoomGrid", OperRoomVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationAttractionsByGroup(string GroupCode)
        {
            OprManager = new OperationManager();
            OperationAttractionsGridViewModel AttractionsModel = new OperationAttractionsGridViewModel();
            ResetAllAttractionsProp(AttractionsModel);
            if (OprManager.CheckGroupCodeRegion(GroupCode, UserRegions))
                AttractionsModel.AttractionsSearchGroupCode = GroupCode;
            var OperAttractionsVModel = SearchOperationAttractionsGridDatainit(AttractionsModel);
            this.SetPermission(OperAttractionsVModel, AllPermVModel);
            if (OperAttractionsVModel.AttractionsPageNumber > 1)
            {
                OperAttractionsVModel.IsAttractionsCanPrev = true;
            }
            else
            {
                OperAttractionsVModel.IsAttractionsCanPrev = false;
            }
            if (OperAttractionsVModel.AttractionsPageNumber < OperAttractionsVModel.AttractionsCountCheck)
            {
                OperAttractionsVModel.IsAttractionsCanNext = true;
            }
            else
            {
                OperAttractionsVModel.IsAttractionsCanNext = false;
            }
            return PartialView("OperationAttractionsGrid", OperAttractionsVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationMiscByGroup(string GroupCode)
        {
            OprManager = new OperationManager();
            OperationMiscGridViewModel MiscModel = new OperationMiscGridViewModel();
            ResetAllMiscProp(MiscModel);
            if (OprManager.CheckGroupCodeRegion(GroupCode, UserRegions))
                MiscModel.MiscSearchGroupCode = GroupCode;
            var OperMiscVModel = SearchOperationMiscGridDatainit(MiscModel);
            this.SetPermission(OperMiscVModel, AllPermVModel);
            if (OperMiscVModel.MiscPageNumber > 1)
            {
                OperMiscVModel.IsMiscCanPrev = true;
            }
            else
            {
                OperMiscVModel.IsMiscCanPrev = false;
            }
            if (OperMiscVModel.MiscPageNumber < OperMiscVModel.MiscCountCheck)
            {
                OperMiscVModel.IsMiscCanNext = true;
            }
            else
            {
                OperMiscVModel.IsMiscCanNext = false;
            }
            return PartialView("OperationMiscGrid", OperMiscVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationBusByGroup(string GroupCode)
        {
            OprManager = new OperationManager();
            OperationBusGridViewModel BusModel = new OperationBusGridViewModel();
            ResetAllBusProp(BusModel);
            if (OprManager.CheckGroupCodeRegion(GroupCode, UserRegions))
                BusModel.BusSearchGroupCode = GroupCode;
            var OperBusVModel = SearchOperationBusGridDatainit(BusModel);
            this.SetPermission(OperBusVModel, AllPermVModel);
            if (OperBusVModel.BusPageNumber > 1)
            {
                OperBusVModel.IsBusCanPrev = true;
            }
            else
            {
                OperBusVModel.IsBusCanPrev = false;
            }
            if (OperBusVModel.BusPageNumber < OperBusVModel.BusCountCheck)
            {
                OperBusVModel.IsBusCanNext = true;
            }
            else
            {
                OperBusVModel.IsBusCanNext = false;
            }
            return PartialView("OperationBusGrid", OperBusVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationGroupCheckListByGroup(string GroupCode)
        {
            OprManager = new OperationManager();
            OperationGroupCheckListGridViewModel GroupCheckListModel = new OperationGroupCheckListGridViewModel();
            ResetAllGroupCheckListProp(GroupCheckListModel);
            if (OprManager.CheckGroupCodeRegion(GroupCode, UserRegions))
                GroupCheckListModel.GroupCheckListSearchGroupCode = GroupCode;
            var OperGroupCheckListVModel = SearchOperationGroupCheckListGridDatainit(GroupCheckListModel);
            this.SetPermission(OperGroupCheckListVModel, AllPermVModel);
            if (OperGroupCheckListVModel.Rows.Count != ((OperGroupCheckListVModel.GroupCheckListPageNumber == 0) ? 1 : OperGroupCheckListVModel.GroupCheckListPageNumber * OperationGroupCheckListGridBData.TakeCount))
            {
                OperGroupCheckListVModel.IsGroupCheckListCanView = false;
            }
            else
            {
                OperGroupCheckListVModel.IsGroupCheckListCanView = true;
            }
            return PartialView("OperationGroupCheckListGrid", OperGroupCheckListVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationRoomGridSaveData(OperationRoomGridViewModel model)
        {
            var OperRoomVModel = OperationRoomGridSaveDatainit(model);
            this.SetPermission(OperRoomVModel, AllPermVModel);
            return PartialView("OperationRoomGrid", OperRoomVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationAttractions(OperationAttractionsGridViewModel model)
        {
            if (model.AttractionsPageNumber == 0)
                ResetAllAttractionsProp(model);
            var OperAttractionsVModel = LoadOperationAttractionsGridDatainit(model);
            this.SetPermission(OperAttractionsVModel, AllPermVModel);
            if (model.AttractionsPageNumber > 1)
            {
                OperAttractionsVModel.IsAttractionsCanPrev = true;
            }
            else
            {
                OperAttractionsVModel.IsAttractionsCanPrev = false;
            }
            if (model.AttractionsPageNumber < OperAttractionsVModel.AttractionsCountCheck)
            {
                OperAttractionsVModel.IsAttractionsCanNext = true;
            }
            else
            {
                OperAttractionsVModel.IsAttractionsCanNext = false;
            }
            return PartialView("OperationAttractionsGrid", OperAttractionsVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationAttractionsGridData(OperationAttractionsGridViewModel model)
        {
            ModelState.Clear();
            if (model.IsAttractionsSearch || model.IsAttractionsView)
            {
                var OperAttractionsVModel = SearchOperationAttractionsGridDatainit(model);
                this.SetPermission(OperAttractionsVModel, AllPermVModel);
                if (model.AttractionsPageNumber > 1)
                {
                    OperAttractionsVModel.IsAttractionsCanPrev = true;
                }
                else
                {
                    OperAttractionsVModel.IsAttractionsCanPrev = false;
                }
                if (model.AttractionsPageNumber < OperAttractionsVModel.AttractionsCountCheck)
                {
                    OperAttractionsVModel.IsAttractionsCanNext = true;
                }
                else
                {
                    OperAttractionsVModel.IsAttractionsCanNext = false;
                }
                return PartialView("OperationAttractionsGrid", OperAttractionsVModel);
            }
            if (model.IsAttractionsFilter)
            {
                var OperAttractionsVModel = OperationAttractionsGridFilterDatainit(model);
                this.SetPermission(OperAttractionsVModel, AllPermVModel);
                if (model.AttractionsPageNumber > 1)
                {
                    OperAttractionsVModel.IsAttractionsCanPrev = true;
                }
                else
                {
                    OperAttractionsVModel.IsAttractionsCanPrev = false;
                }
                if (model.AttractionsPageNumber < OperAttractionsVModel.AttractionsCountCheck)
                {
                    OperAttractionsVModel.IsAttractionsCanNext = true;
                }
                else
                {
                    OperAttractionsVModel.IsAttractionsCanNext = false;
                }
                return PartialView("OperationAttractionsGrid", OperAttractionsVModel);
            }
            return PartialView();
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationAttractionsGridSaveData(OperationAttractionsGridViewModel model)
        {
            var OperAttractionsVModel = OperationAttractionsGridSaveDatainit(model);
            this.SetPermission(OperAttractionsVModel, AllPermVModel);
            if (model.AttractionsPageNumber > 1)
            {
                OperAttractionsVModel.IsAttractionsCanPrev = true;
            }
            else
            {
                OperAttractionsVModel.IsAttractionsCanPrev = false;
            }
            if (model.AttractionsPageNumber < OperAttractionsVModel.AttractionsCountCheck)
            {
                OperAttractionsVModel.IsAttractionsCanNext = true;
            }
            else
            {
                OperAttractionsVModel.IsAttractionsCanNext = false;
            }
            return PartialView("OperationAttractionsGrid", OperAttractionsVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationMisc(OperationMiscGridViewModel model)
        {
            if (model.MiscPageNumber == 0)
                ResetAllMiscProp(model);
            var OperMiscVModel = LoadOperationMiscGridDatainit(model);
            this.SetPermission(OperMiscVModel, AllPermVModel);
            if (model.MiscPageNumber > 1)
            {
                OperMiscVModel.IsMiscCanPrev = true;
            }
            else
            {
                OperMiscVModel.IsMiscCanPrev = false;
            }
            if (model.MiscPageNumber < OperMiscVModel.MiscCountCheck)
            {
                OperMiscVModel.IsMiscCanNext = true;
            }
            else
            {
                OperMiscVModel.IsMiscCanNext = false;
            }
            return PartialView("OperationMiscGrid", OperMiscVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationMiscGridData(OperationMiscGridViewModel model)
        {
            ModelState.Clear();
            if (model.IsMiscSearch || model.IsMiscView)
            {
                var OperMiscVModel = SearchOperationMiscGridDatainit(model);
                this.SetPermission(OperMiscVModel, AllPermVModel);
                if (model.MiscPageNumber > 1)
                {
                    OperMiscVModel.IsMiscCanPrev = true;
                }
                else
                {
                    OperMiscVModel.IsMiscCanPrev = false;
                }
                if (model.MiscPageNumber < OperMiscVModel.MiscCountCheck)
                {
                    OperMiscVModel.IsMiscCanNext = true;
                }
                else
                {
                    OperMiscVModel.IsMiscCanNext = false;
                }
                return PartialView("OperationMiscGrid", OperMiscVModel);
            }
            if (model.IsMiscFilter)
            {
                var OperMiscVModel = OperationMiscGridFilterDatainit(model);
                this.SetPermission(OperMiscVModel, AllPermVModel);
                if (model.MiscPageNumber > 1)
                {
                    OperMiscVModel.IsMiscCanPrev = true;
                }
                else
                {
                    OperMiscVModel.IsMiscCanPrev = false;
                }
                if (model.MiscPageNumber < OperMiscVModel.MiscCountCheck)
                {
                    OperMiscVModel.IsMiscCanNext = true;
                }
                else
                {
                    OperMiscVModel.IsMiscCanNext = false;
                }
                return PartialView("OperationMiscGrid", OperMiscVModel);
            }
            return PartialView();
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationMiscGridSaveData(OperationMiscGridViewModel model)
        {
            var OperMiscVModel = OperationMiscGridSaveDatainit(model);
            this.SetPermission(OperMiscVModel, AllPermVModel);
            if (model.MiscPageNumber > 1)
            {
                OperMiscVModel.IsMiscCanPrev = true;
            }
            else
            {
                OperMiscVModel.IsMiscCanPrev = false;
            }
            if (model.MiscPageNumber < OperMiscVModel.MiscCountCheck)
            {
                OperMiscVModel.IsMiscCanNext = true;
            }
            else
            {
                OperMiscVModel.IsMiscCanNext = false;
            }
            return PartialView("OperationMiscGrid", OperMiscVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationBus(OperationBusGridViewModel model)
        {
            if (model.BusPageNumber == 0)
                 ResetAllBusProp(model);
            var OperBusVModel = LoadOperationBusGridDatainit(model);
            this.SetPermission(OperBusVModel, AllPermVModel);
            if (model.BusPageNumber > 1)
            {
                OperBusVModel.IsBusCanPrev = true;
            }
            else
            {
                OperBusVModel.IsBusCanPrev = false;
            }
            if (OperBusVModel.BusPageNumber < OperBusVModel.BusCountCheck)
            {
                OperBusVModel.IsBusCanNext = true;
            }
            else
            {
                OperBusVModel.IsBusCanNext = false;
            }
            return PartialView("OperationBusGrid", OperBusVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationBusGridData(OperationBusGridViewModel model)
        {
            ModelState.Clear();
            if (model.IsBusSearch || model.IsBusView)
            {
                var OperBusVModel = SearchOperationBusGridDatainit(model);
                this.SetPermission(OperBusVModel, AllPermVModel);
                if (model.BusPageNumber > 1)
                {
                    OperBusVModel.IsBusCanPrev = true;
                }
                else
                {
                    OperBusVModel.IsBusCanPrev = false;
                }
                if (OperBusVModel.BusPageNumber < OperBusVModel.BusCountCheck)
                {
                    OperBusVModel.IsBusCanNext = true;
                }
                else
                {
                    OperBusVModel.IsBusCanNext = false;
                }
                return PartialView("OperationBusGrid", OperBusVModel);
            }
            if (model.IsBusFilter)
            {
                var OperBusVModel = OperationBusGridFilterDatainit(model);
                this.SetPermission(OperBusVModel, AllPermVModel);
                if (model.BusPageNumber > 1)
                {
                    OperBusVModel.IsBusCanPrev = true;
                }
                else
                {
                    OperBusVModel.IsBusCanPrev = false;
                }
                if (OperBusVModel.BusPageNumber < OperBusVModel.BusCountCheck)
                {
                    OperBusVModel.IsBusCanNext = true;
                }
                else
                {
                    OperBusVModel.IsBusCanNext = false;
                }
                return PartialView("OperationBusGrid", OperBusVModel);
            }
            return PartialView();
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationBusGridSaveData(OperationBusGridViewModel model)
        {
            var OperBusVModel = OperationBusGridSaveDatainit(model);
            this.SetPermission(OperBusVModel, AllPermVModel);
            if (model.BusPageNumber > 1)
            {
                OperBusVModel.IsBusCanPrev = true;
            }
            else
            {
                OperBusVModel.IsBusCanPrev = false;
            }
            if (OperBusVModel.BusPageNumber < OperBusVModel.BusCountCheck)
            {
                OperBusVModel.IsBusCanNext = true;
            }
            else
            {
                OperBusVModel.IsBusCanNext = false;
            }
            return PartialView("OperationBusGrid", OperBusVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationTechProg(OperationTechProgGridViewModel model)
        {
            if (!model.TechProgIsSearch)
            {
                ResetAllTechProgProp(model);
                OperationTechProgGridViewModel OperTechProgGridView = new OperationTechProgGridViewModel();
                OperTechProgGridView.TechProgFilterType = new List<CheckBoxControlViewModel>();
                OperTechProgGridView.Rows = new List<OperationTechProgGridRowViewModel>();
                OperationTechProgInitModelState(OperTechProgGridView, model);
                this.SetPermission(OperTechProgGridView, AllPermVModel);
                return PartialView("OperationTechProgGrid", OperTechProgGridView);
            }
            var OperTechProgVModel = LoadOperationTechProgGridDatainit(model);
            this.SetPermission(OperTechProgVModel, AllPermVModel);
            return PartialView("OperationTechProgGrid", OperTechProgVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationTechProgGridData(OperationTechProgGridViewModel model)
        {
            ModelState.Clear();
            if (model.IsTechProgView)
            {
                this.SetPermission(model, AllPermVModel);
                return LoadOperationTechProg(model);
            }
            if (model.TechProgIsSearch)
            {
                var OperTechProgVModel = SearchOperationTechProgGridDatainit(model);
                this.SetPermission(OperTechProgVModel, AllPermVModel);
                return PartialView("OperationTechProgGrid", OperTechProgVModel);
            }
            if (model.IsTechProgFilter)
            {
                var OperTechProgVModel = SearchOperationTechProgGridDatainit(model);
                this.SetPermission(OperTechProgVModel, AllPermVModel);
                return PartialView("OperationTechProgGrid", OperTechProgVModel);
            }

            var OperTechProgVModelGlobal = OperationTechProgGridSaveDatainit(model);
            this.SetPermission(OperTechProgVModelGlobal, AllPermVModel);
            return PartialView("OperationTechProgGrid", OperTechProgVModelGlobal);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationTechProgByGroup(string GroupCode)
        {
            OprManager = new OperationManager();
            OperationTechProgGridViewModel TechProgModel = new OperationTechProgGridViewModel();
            ResetAllTechProgProp(TechProgModel);
            if(OprManager.CheckGroupCodeRegion(GroupCode, UserRegions))
                TechProgModel.TechProgSearchGroupCode = GroupCode;
            var OperTechProgVModel = SearchOperationTechProgGridDatainit(TechProgModel);
            this.SetPermission(OperTechProgVModel, AllPermVModel);
            return PartialView("OperationTechProgGrid", OperTechProgVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult ValidateOperationTechProg(string GroupCode)
        {
            var OperTechProgVModel = ValidateOperationTechProgGridDatainit(GroupCode);
            OperTechProgVModel.TechProgSearchGroupCode = GroupCode;
            ResetAllTechProgProp(OperTechProgVModel);
            this.SetPermission(OperTechProgVModel, AllPermVModel);
            return PartialView("OperationTechProgGrid", OperTechProgVModel);  
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationTechProgGridSaveData(OperationTechProgGridViewModel model)
        {
            var OperTechProgVModel = OperationTechProgGridSaveDatainit(model);
            OperTechProgVModel.TechProgSearchGroupCode = model.TechProgSearchGroupCode;
            OperTechProgVModel.TechProgGroupIDTxt = model.TechProgGroupIDTxt;
            this.SetPermission(OperTechProgVModel, AllPermVModel);
            return PartialView("OperationTechProgGrid", OperTechProgVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationGroupCheckList(OperationGroupCheckListGridViewModel model)
        {
            if (model.GroupCheckListPageNumber == 0)
                ResetAllGroupCheckListProp(model);
            var OperGroupCheckListVModel = LoadOperationGroupCheckListGridDatainit(model, User.Identity.Name);
            this.SetPermission(OperGroupCheckListVModel, AllPermVModel);
            if (OperGroupCheckListVModel.Rows.Count != model.GroupCheckListPageNumber * OperationGroupCheckListGridBData.TakeCount)
            {
                OperGroupCheckListVModel.IsGroupCheckListCanView = false;
            }
            else
            {
                OperGroupCheckListVModel.IsGroupCheckListCanView = true;
            }

            return PartialView("OperationGroupCheckListGrid", OperGroupCheckListVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationGroupCheckListGridData(OperationGroupCheckListGridViewModel model)
        {
            ModelState.Clear();
            if (model.IsGroupCheckListView)
            {
                this.SetPermission(model, AllPermVModel);
                return LoadOperationGroupCheckList(model);
            }
            if (model.IsGroupCheckListSearch)
            {
                var OperGroupCheckListVModel = SearchOperationGroupCheckListGridDatainit(model);
                this.SetPermission(OperGroupCheckListVModel, AllPermVModel);
                if (OperGroupCheckListVModel.Rows.Count != model.GroupCheckListPageNumber * OperationGroupCheckListGridBData.TakeCount)
                {
                    OperGroupCheckListVModel.IsGroupCheckListCanView = false;
                }
                else
                {
                    OperGroupCheckListVModel.IsGroupCheckListCanView = true;
                }
                return PartialView("OperationGroupCheckListGrid", OperGroupCheckListVModel);
            }
            if (model.IsGroupCheckListFilter)
            {
                var OperGroupCheckListVModel = OperationGroupCheckListGridFilterDatainit(model);
                this.SetPermission(OperGroupCheckListVModel, AllPermVModel);
                if (OperGroupCheckListVModel.Rows.Count != model.GroupCheckListPageNumber * OperationGroupCheckListGridBData.TakeCount)
                {
                    OperGroupCheckListVModel.IsGroupCheckListCanView = false;
                }
                else
                {
                    OperGroupCheckListVModel.IsGroupCheckListCanView = true;
                }
                return PartialView("OperationGroupCheckListGrid", OperGroupCheckListVModel);
            }
            return PartialView();
        }
        public PartialViewResult LoadGirPricesByQuotaID(int QuotaID, int GroupID)
        {
            OprManager = new OperationManager();
            var PriceBData = OprManager.OperationLoadGirPrices(QuotaID, GroupID);
            OperationGirGroupPriceGridViewModel PriceVModel = new OperationGirGroupPriceGridViewModel();
            PriceVModel.Rows = new List<OperationGirGroupPriceGridRowViewModel>();
            foreach (var row in PriceBData.Rows)
                PriceVModel.Rows.Add(new OperationGirGroupPriceGridRowViewModel
                {
                    PriceCustomer = row.Customer,
                    PriceCustomerID = row.CustomerID.ToString(),
                    PriceArrivalDate = row.ArrivalDate != null ? Convert.ToDateTime(row.ArrivalDate).ToString("dd/MMM/yy"):"",
                    PriceGroupCode = row.GroupCode,
                    PriceGroupID = row.GroupID,
                    PriceGroupName = row.GroupName,
                    PricePricePerPerson = row.PricePerPerson != null ? Convert.ToDecimal(row.PricePerPerson).ToString("F") : "",
                    PricePriceFBoard = row.PriceFBoard != null ? Convert.ToDecimal(row.PriceFBoard).ToString("F") : "",
                    PricePriceSingleSup = row.PriceSingleSup != null ? Convert.ToDecimal(row.PriceSingleSup).ToString("F") : "",
                    PricePricePerPersonCad = row.PricePerPersonCad != null ? Convert.ToDecimal(row.PricePerPersonCad).ToString("F") : "",
                    PricePriceFBoardCad = row.PriceFBoardCad != null ? Convert.ToDecimal(row.PriceFBoardCad).ToString("F") : "",
                    PricePriceSingleSupCad = row.PriceSingleSupCad != null ? Convert.ToDecimal(row.PriceSingleSupCad).ToString("F") : "",
                });
            return PartialView("OperationGirGroupPricesGrid", PriceVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationSaveGirGroupPrices(OperationGirGroupPriceGridViewModel model)
        {
            OprManager = new OperationManager();
            var GirPricesBData = new OperationGirGroupPricesGridBData();
            GirPricesBData.Rows = new List<OperationGirGroupPricesGridRowBData>();
            foreach(var row in model.Rows)
            {
                GirPricesBData.Rows.Add(new OperationGirGroupPricesGridRowBData()
                {
                    GroupID = row.PriceGroupID,
                    CustomerID = row.PriceCustomerID != null ? Convert.ToInt32(row.PriceCustomerID) : 0, 
                    PricePerPerson = row.PricePricePerPerson != null ? Convert.ToDecimal(row.PricePricePerPerson): (decimal?)null, 
                    PriceSingleSup = row.PricePriceSingleSup != null ? Convert.ToDecimal(row.PricePriceSingleSup): (decimal?)null,
                    PriceFBoard = row.PricePriceFBoard != null ? Convert.ToDecimal(row.PricePriceFBoard): (decimal?)null,
                    PricePerPersonCad = row.PricePricePerPersonCad != null ? Convert.ToDecimal(row.PricePricePerPersonCad) : (decimal?)null,
                    PriceSingleSupCad = row.PricePriceSingleSupCad != null ? Convert.ToDecimal(row.PricePriceSingleSupCad) : (decimal?)null,
                    PriceFBoardCad = row.PricePriceFBoardCad != null ? Convert.ToDecimal(row.PricePriceFBoardCad) : (decimal?)null,    
                });
            }
            var PriceBData = OprManager.OperationSaveGirPrices(GirPricesBData);
            var PriceVModel = new OperationGirGroupPriceGridViewModel();
            return PartialView("OperationGirGroupPricesGrid", PriceVModel);
        }

        [Authorize]
        [HttpPost]
        public PartialViewResult AutoComplete(string PropName, string keyword)
        {
            OprManager = new OperationManager();
            var data = OprManager.FindKeywordInEntity(PropName, keyword, UserRegions);
            AutoCompleteViewModel AutoCompVMode = new AutoCompleteViewModel() { Items = data};
            return PartialView("AutoComplete", AutoCompVMode);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult RoomSearchComplete(string PropName, string keyword, string tab)
        {
            OprManager = new OperationManager();
            var data = OprManager.OperationRoomSearchComplete(PropName, keyword, UserRegions);
            OperationRoomSearchCompleteViewModel AutoCompVMode = new OperationRoomSearchCompleteViewModel() { ControlName = data.ControlName};
            AutoCompVMode.Rows = new List<OperationRoomSearchCompleteRowViewModel>();
            foreach (var row in data.Rows)
                AutoCompVMode.Rows.Add(new OperationRoomSearchCompleteRowViewModel { Customer = row.IsGir == true ? "Gir" : row.Customer, GroupCode = row.GroupCode, GroupId = row.GroupId, GroupName = row.GroupName });
            if(tab == "Invoice")
                return PartialView("OperationInvoiceSearchComplete", AutoCompVMode);
            else
            return PartialView("OperationRoomSearchComplete", AutoCompVMode);
        }

        #region Vendor Confirmation
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadVendorHotel(int GroupID)
        {
            OprManager = new OperationManager();
            var data = OprManager.OperationVendorHotelGridLoad(GroupID);
            return PartialView("OperationVendorHotelGrid", InitOperVHotelGridViewModel(data));
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult UpdateVendorHotel(OperationVHotelGridViewModel model)
        {
            OprManager = new OperationManager();

            return PartialView("OperationVendorHotelGrid", model);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadGroupVendorConfirmation(int GroupID, int VendorID)
        {
            OprManager = new OperationManager();
            var data = OprManager.OperationGroupVendorGridLoad(GroupID, VendorID);
            var LoadGroupVendorConfVModel = InitOperGroupVendorGridViewModel(data);
            LoadGroupVendorConfVModel.GVendorGroupID = GroupID;
            LoadGroupVendorConfVModel.GVendorVendorID = VendorID;
            return PartialView("OperationGroupVendorGrid", LoadGroupVendorConfVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationGroupVendorGridDataSave(OperationGroupVendorGridViewModel model)
        {
            OprManager = new OperationManager();
            var SaveGroupRoomBData = InitOperationGVendorRoomGridBData(model);
            var data = OprManager.OperationGroupVendorGridSave(SaveGroupRoomBData);
            var GroupVendorGridVM = InitOperGroupVendorGridViewModel(data);
            if (data.Error.Message != null)
                GroupVendorGridVM.OperGVendorRoomMessageInfo = data.Error.Message;
            return PartialView("OperationGroupVendorGrid", GroupVendorGridVM);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationGroupVendorGridData(OperationGroupVendorGridViewModel model)
        {
            OprManager = new OperationManager();
            if(model.GVendorIsRoomRemove)
            {
                var data = OprManager.RemoveOperationGroupVendorRooms(model.GVendorRemoveGroupID, model.GVendorRemoveVendorID, Convert.ToDateTime(model.GVendorArrivalDate), model.GVendorRemoveLineNo);
                var GroupVendorGridVM = InitOperGroupVendorGridViewModel(data);
                if (data.Error.Message != null)
                    GroupVendorGridVM.OperGVendorRoomMessageInfo = data.Error.Message;
                return PartialView("OperationGroupVendorGrid", GroupVendorGridVM);
            }
            return PartialView();          
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadAttrBusConfirmation(int GroupID, int VendorID, DateTime ArrivalDate, string VendorType)
        {
            OprManager = new OperationManager();
            var data = OprManager.OperationAttrBusConfirmationGridLoad(GroupID, VendorID, ArrivalDate, VendorType);
            return PartialView("OperationAttrBusConfirmation", InitOperAttrBusConfirmationGridViewModel(data, VendorType));
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationAttrBusConfirmGridSaveData(OperationAttrBusConfirmationViewModel model)
        {
            OprManager = new OperationManager();
            var ConfBData = InitOperationAttrBusConfirmGridBData(model);
            var data = OprManager.SaveOperationAttrBusConfirm(ConfBData);
            return PartialView("OperationAttrBusConfirmation", InitOperAttrBusConfirmationGridViewModel(data, model.AttrBusVendorType));
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult LoadVendorConfirmation(int GroupID, int VendorID, DateTime ArrivalDate)
        {
            OprManager = new OperationManager();
            var data = OprManager.OperationVendorConfirmationGridLoad(GroupID, VendorID, ArrivalDate);
            return PartialView("OperationVendorConfirmation", InitOperVendorConfirmationGridViewModel(data));
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationVConfirmGridSaveData(OperationVendorConfirmationViewModel model)
        {
            OprManager = new OperationManager();
            var ConfBData = InitOperationVendorConfirmGridBData(model);
            var data = OprManager.SaveOperationVendorConfirm(ConfBData);
            return PartialView("OperationVendorConfirmation", InitOperVendorConfirmationGridViewModel(data));
        }
        [Authorize]
        [HttpPost]
        public JsonResult OperationVConfirmUpdateProvide(int GroupID, int VendorID, DateTime ArrivalDate)
        {
            OprManager = new OperationManager();
            var data = OprManager.OperationVendorConfirmUpdateProvide(GroupID, VendorID, ArrivalDate);
            return this.Json(data);
        }
        [Authorize]
        [HttpPost]
        public ActionResult UploadVendorConfirmFile(string VendorID, string GroupID, string VendorType, bool UpdateAll)
        {
            OprManager = new OperationManager();
            bool isUploaded = false;
            string message = "File upload failed";
            if(Request.Files.Count == 1)
            {
                var myFile = Request.Files[0];
                if (myFile != null && myFile.ContentLength != 0)
                {
                    if (
                        Path.GetExtension(myFile.FileName) != ".pdf"
                        && Path.GetExtension(myFile.FileName) != ".jpg"
                        && Path.GetExtension(myFile.FileName) != ".gif"
                        && Path.GetExtension(myFile.FileName) != ".png"
                        && Path.GetExtension(myFile.FileName) != ".docx"
                        && Path.GetExtension(myFile.FileName) != ".doc"
                        && Path.GetExtension(myFile.FileName) != ".txt"
                        && Path.GetExtension(myFile.FileName) != ".xlsx"
                        && Path.GetExtension(myFile.FileName) != ".xls")
                    {
                        message = "Upload File must be one of the following file types: pdf, jpg, gif, png, docx, doc, txt, xlsx, xls.";
                    }

                    if (myFile.ContentLength > 2048 * 1024)
                    {
                        message = "Upload File can not be larger than 2MB each.";
                    }
                    string content = System.Configuration.ConfigurationManager.AppSettings["UploadVendorConfirmContract"];
                    string pathForSaving = Server.MapPath(content + "/" + VendorID + "/" + GroupID);
                    if (CreateFolderIfNeeded(pathForSaving))
                    {
                        try
                        {
                            string FileName = ValidFileName(myFile.FileName);
                            myFile.SaveAs(Path.Combine(pathForSaving, FileName));
                            isUploaded = true;
                            message = "File uploaded successfully!";
                            OprManager.UpdateVendorConfirmPath(Convert.ToInt32(VendorID), Convert.ToInt32(GroupID), Path.Combine("//" + VendorID + "//" + GroupID + "//", FileName), VendorType, UpdateAll);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.ToMessageAndCompleteStacktrace());
                            message = string.Format("File upload failed: {0}", ex.Message);
                        }
                    }
                }

            }
            return Json(new { isUploaded = isUploaded, message = message }, "text/html");
        }
        [Authorize]
        [HttpGet]
        public FileResult DownloadVendorConfirmFile(string FileName)
        {
            string FileUrl = "~/" + System.Configuration.ConfigurationManager.AppSettings["UploadVendorConfirmContract"] + FileName;
            string content = System.Web.Hosting.HostingEnvironment.MapPath(FileUrl);
            try
            {
                return File(System.IO.File.ReadAllBytes(content), System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(content));
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }
        }
        #endregion

        #region Invoice tab

        [Authorize]
        [HttpPost]
        public PartialViewResult LoadOperationInvoice(OperationInvoiceViewModel model)
        {
            OprManager = new OperationManager();
            if (!model.IsInvLoad)
            {
                OperationInvoiceViewModel OperInvView = new OperationInvoiceViewModel();
                var InvBData = OprManager.OperationLoadInvoiceByGroupID(model.InvGroupID);
                var InvViewModel = InitOperationInvoiceViewModel(InvBData);
                InvViewModel.InvoiceGroupID = model.InvGroupID;
                this.SetPermission(InvViewModel, AllPermVModel);
                return PartialView("OperationInvoice", InvViewModel);
            }
          //  var OperRoomVModel = LoadOperationRoomGridDatainit(model);
          //  return PartialView("OperationRoomGrid", OperRoomVModel);
            return PartialView();
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationInvoice(OperationInvoiceViewModel model)
        {
            ModelState.Clear();
            OprManager = new OperationManager();
            if (model.IsInvSearch)
            {
                OperationInvoiceViewModel OperInvView = new OperationInvoiceViewModel();
                var InvBData = OprManager.OperationLoadInvoiceByGroupID(model.InvGroupID);
                var InvViewModel = InitOperationInvoiceViewModel(InvBData);
                InvViewModel.IsInvSearch = model.IsInvSearch;
                InvViewModel.InvoiceGroupID = model.InvGroupID;
                this.SetPermission(InvViewModel, AllPermVModel);
                return PartialView("OperationInvoice", InvViewModel);
            }
            if (model.IsInvRemove)
            {
                OperationInvoiceViewModel OperInvView = new OperationInvoiceViewModel();
                var InvBData = model.InvIsGroupGir == true ? OprManager.OperationRemoveInvoice(model.InvoiceGroupID, model.InvoiceLineNo, model.InvoiceCustomerID) : OprManager.OperationRemoveInvoice(model.InvoiceGroupID, model.InvoiceLineNo);
                var InvViewModel = InitOperationInvoiceViewModel(InvBData);
                InvViewModel.IsInvSearch = true;
                InvViewModel.InvoiceGroupID = model.InvoiceGroupID;
                this.SetPermission(InvViewModel, AllPermVModel);
                return PartialView("OperationInvoice", InvViewModel);
            }
            return PartialView();
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult OperationInvoiceSaveData(OperationInvoiceViewModel model)
        {
            OprManager = new OperationManager();
            OperationInvoiceViewModel OperInvView = new OperationInvoiceViewModel();
            var InvBData = OprManager.SaveOperationInvoice(InitOperationInvoiceBData(model));
            var InvViewModel = InitOperationInvoiceViewModel(InvBData);
            InvViewModel.IsInvSearch = true;
            InvViewModel.InvoiceGroupID = model.InvoiceGroupID;
            this.SetPermission(InvViewModel, AllPermVModel);
            return PartialView("OperationInvoice", InvViewModel);
           
        }
        [Authorize]
        [HttpGet]
        public PartialViewResult LoadOperationInvoice(int GroupID)
        {
            OprManager = new OperationManager();
            var InvBData = OprManager.OperationLoadInvoiceByGroupID(GroupID);
            var InvViewModel = InitOperationInvoiceViewModel(InvBData);
            InvViewModel.IsInvSearch = true;
            this.SetPermission(InvViewModel, AllPermVModel);
            return PartialView("OperationInvoice", InvViewModel);
        }
        [Authorize]
        [HttpGet]
        public PartialViewResult LoadOperationGirInvoice(int GroupID, int CustomerID)
        {
            OprManager = new OperationManager();
            var InvBData = OprManager.OperationLoadGirInvoice(GroupID, CustomerID);
            var InvViewModel = InitOperationInvoiceViewModel(InvBData);
            InvViewModel.IsInvSearch = true;
            this.SetPermission(InvViewModel, AllPermVModel);
            return PartialView("OperationInvoice", InvViewModel);
        }
        [Authorize]
        [HttpGet]
        public PartialViewResult LoadQuotaPricesByQuotaID(string QuotaID)
        {
            QuotationManager QM = new QuotationManager();
            QuotationCostPriceGridViewModel QuotaCPriceVModel = new QuotationCostPriceGridViewModel();
            QuotaCPriceVModel.Rows = new List<QuotationCostPriceGridRowViewModel>();
            var QuotaCostBdata = QM.LoadQuotaCostPriceGrid(QuotaID, null);
            if (QuotaCostBdata.SSupSumCad != 0)
                QuotaCPriceVModel.SSSum = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSum)).ToString() + " USD, " + Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumCad)).ToString() + " CAD";
            else
                QuotaCPriceVModel.SSSum = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSum)).ToString() + " USD";
            if (QuotaCostBdata.SSupSumCadFinal != 0)
            {
                QuotaCPriceVModel.SSSumFinal = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumFinal)).ToString() + " USD, ";
                QuotaCPriceVModel.SSSumFinalCad = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumCadFinal)).ToString() + " CAD";
            }
            else
            {
                QuotaCPriceVModel.SSSumFinal = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSum)).ToString() + " USD";
                QuotaCPriceVModel.SSSumFinalCad = "";
            }
            if (QuotaCostBdata != null && QuotaCostBdata.Rows != null)
                foreach (var cost in QuotaCostBdata.Rows)
                    QuotaCPriceVModel.Rows.Add(new QuotationCostPriceGridRowViewModel()
                    {
                        GivenFree = Convert.ToDecimal(cost.GivenFree).ToString("F"),
                        GivenSold = Math.Round(Convert.ToDecimal(cost.GivenSold)).ToString(),
                        LineNo = cost.LineNo.ToString(),
                        PaxL = cost.PaxL.ToString(),
                        Sold = Math.Round(Convert.ToDecimal(cost.Sold)).ToString(),
                        CurrencyCostPrice = cost.Currency,
                        FAdjust = Convert.ToDecimal(cost.FAdjst).ToString("F"),
                        FinalPrice = Math.Round(Convert.ToDecimal(cost.FPrice)).ToString(),
                    });
            if (QuotaID != null || QuotaID != "")
            {
                string proposalDirPath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ProposalPath"]) + "//" + QuotaID;
                if (Directory.Exists(proposalDirPath))
                {
                    System.IO.DirectoryInfo proposalDir = new System.IO.DirectoryInfo(proposalDirPath);
                    int FileCount = proposalDir.GetFiles().Length;
                    if (FileCount == 1)
                    {
                        try
                        {
                            QuotaCPriceVModel.Proposal = System.Configuration.ConfigurationManager.AppSettings["ProposalPath"] + "//" + QuotaID + "//" + new DirectoryInfo(proposalDirPath).GetFiles().Select(o => o.Name).SingleOrDefault();
                            QuotaCPriceVModel.HasProposal = true;
                            QuotaCPriceVModel.CostPriceQuotaID = QuotaID;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.ToMessageAndCompleteStacktrace());
                            QuotaCPriceVModel.HasProposal = false;
                            QuotaCPriceVModel.CostPriceQuotaID = QuotaID;
                        }
                    }
                    else
                    {
                        QuotaCPriceVModel.HasProposal = false;
                        QuotaCPriceVModel.CostPriceQuotaID = QuotaID;
                    }
                }
                else
                {
                    QuotaCPriceVModel.HasProposal = false;
                    QuotaCPriceVModel.CostPriceQuotaID = QuotaID;
                }
            }
            else
            {
                        QuotaCPriceVModel.HasProposal = false;
                        QuotaCPriceVModel.CostPriceQuotaID = QuotaID;
            }
            return PartialView("OperationInvQuotaPricesGrid", QuotaCPriceVModel);
        }
        [Authorize]
        [HttpGet]
        public ActionResult ViewProposal(string QuotaID)
        {

            string proposalDirPath;
            System.IO.DirectoryInfo proposalDir;
            int FileCount;
            string fileName = "";
            byte[] fileBytes = null;
            if (QuotaID != null || QuotaID != "")
            {
                proposalDirPath = System.Configuration.ConfigurationManager.AppSettings["ProposalPath"] + "\\" + QuotaID;
                proposalDir = new System.IO.DirectoryInfo(proposalDirPath);
                FileCount = proposalDir.GetFiles().Length;
                if (FileCount == 1)
                {
                    try
                    {

                        fileName = new DirectoryInfo(proposalDirPath).GetFiles().Select(o => o.Name).SingleOrDefault();
                        fileBytes = System.IO.File.ReadAllBytes(proposalDirPath + "\\" + fileName);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToMessageAndCompleteStacktrace());
                        return View("Error");
                    }
                }
                else
                {
                    return View("Error");
                }
            }
            string contentType = MimeMapping.GetMimeMapping(fileName);
            return File(fileBytes, contentType);
        }

        #endregion
        #region Optional Tab
        [Authorize]
        [HttpGet]
        public PartialViewResult LoadOptionalDetails(int VendorID)
        {
            OprManager = new OperationManager();
            var OptionalData = OprManager.LoadOperationOptional(VendorID);
            return PartialView("LoadOperationOptionalDetails", InitOperationOptionalViewModel(OptionalData));
        }
        #region private
        private OperationOptionalViewModel InitOperationOptionalViewModel(OperationOptionalBData Data)
        {
            OperationOptionalViewModel OptionalViewModel = new OperationOptionalViewModel
            {
                OptionalVendorID = Data.VendorID,
            };
            OptionalViewModel.Rows = new List<OperationOptionalDetailsViewModel>();
            if (Data != null && Data.Rows != null)
                foreach (var row in Data.Rows)
                    OptionalViewModel.Rows.Add(new OperationOptionalDetailsViewModel
                    {
                        OptionalID = row.OptionalID,
                        OptionalDetailID = row.OptionalDetailID,
                        OptionalStartDate = row.ContractStartDate.ToString("dd/MMM/yy"),
                        OptionalEndDate = row.ContractEndDate.ToString("dd/MMM/yy"),
                        PaxFrom = row.PaxFrom.ToString(),
                        PaxTo = row.PaxTo.ToString(),
                        SelectedCurrency = row.SelectedCurrency,
                        Price = Convert.ToDecimal(row.Price).ToString("F"),
                        BusIncluded = row.BusIncluded == null ? false : Convert.ToBoolean(row.BusIncluded),
                        GuideIncluded = row.GuideIncluded == null ? false : Convert.ToBoolean(row.GuideIncluded),
                    });
            return OptionalViewModel;
        }
        #endregion
        #endregion
        #region Amex tab
        [Authorize]
        [HttpGet]
        public PartialViewResult LoadOperationAmexVendors(int VendorID, int GroupID, int CardID, int LineNo, string ArrivalDate, string OperationTabName, string Category, string Time)
        {
            OprManager = new OperationManager();
            var AmexData = OprManager.LoadOperationAmexVendors(VendorID, GroupID, CardID, LineNo, Convert.ToDateTime(ArrivalDate), OperationTabName, Category == "" ? null : Category, (Time == "" || Time == null) ? (DateTime?)null : Convert.ToDateTime(Time));
            return PartialView("LoadOperationAmexVendorDetails", InitOperationAmexVendorViewModel(AmexData, ArrivalDate, OperationTabName, Category == "" ? null : Category, (Time == "" || Time == null) ? (DateTime?)null : Convert.ToDateTime(Time)));
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveOperationAmexVendors(OperationAmexVendorViewModel model)
        {
            OprManager = new OperationManager();
            var AmexVendorBD = InitOperationAmexVendorBD(model);
            var EditError = OprManager.SaveOperationAmexVendorDetailsData(AmexVendorBD);
            MessageBoxViewModel MessBoxforEdit = new MessageBoxViewModel()
            {
                Message = EditError.Message != null ? "Error - " + EditError.Message : "",
            };
            return PartialView("MessageBox", MessBoxforEdit);
        }
        #endregion
        #region private Inits
        private string ValidFileName(string FileName)
        {
            return FileName.Replace("#", "_");
        }
        private OperationInvoiceBData InitOperationInvoiceBData(OperationInvoiceViewModel model)
        {
            OperationInvoiceBData InvoiceBData = new OperationInvoiceBData();
            InvoiceBData.Rows = new List<OperationInvoiceGridBData>();
            InvoiceBData.InvoiceGroupID = model.InvoiceGroupID;
            InvoiceBData.InvoiceCustomerID = model.InvoiceCustomerID;
            InvoiceBData.InvoiceComment = model.InvComments;
            InvoiceBData.PerformaComment = model.InvProfComments;
            InvoiceBData.SelectedInvBank = model.SelectedInvBank != null ? Convert.ToInt32(model.SelectedInvBank) : (int?)null;
            InvoiceBData.SelectedInvPaymentTerms = model.SelectedInvPaymentTerms;
            InvoiceBData.SelectedInvSalesPerson = model.SelectedInvSalesPerson != null ? Convert.ToInt32(model.SelectedInvSalesPerson) : (int?)null;
            InvoiceBData.SelectedContactPerson = model.SelectedInvContactPerson != null ? Convert.ToInt32(model.SelectedInvContactPerson) : (int?)null;
            InvoiceBData.InvProforma = model.InvProforma;
            InvoiceBData.InvoiceDate = model.InvoiceDate != null ? Convert.ToDateTime(model.InvoiceDate) : (DateTime?)null;
            InvoiceBData.DepositDue = model.InvDepositDue != null ? Convert.ToDateTime(model.InvDepositDue) : (DateTime?)null;
            InvoiceBData.FinalPayment = model.InvFinalPayment != null ? Convert.ToDateTime(model.InvFinalPayment) : (DateTime?)null;
            InvoiceBData.InvCadUsdRate = model.InvCadUsdRate != null ? Convert.ToDouble(model.InvCadUsdRate) : (double?)null;
            InvoiceBData.DepositM = model.InvDepositM;
            InvoiceBData.DepositAmount = model.InvDepositM == true ? (model.InvDepositAmt != null ? Convert.ToDecimal(model.InvDepositAmt) : (decimal?)null) : 0;
            InvoiceBData.TotalRefund = model.InvTotalRefund != null ? Convert.ToDecimal(model.InvTotalRefund) : (decimal?)null;
            if (model != null && model.Rows != null)
            foreach (var row in model.Rows)
                InvoiceBData.Rows.Add(new OperationInvoiceGridBData
                {
                    Currency = row.InvCurrency,
                    Debit = row.InvDebit != null ? Convert.ToDecimal(row.InvDebit ) : (decimal?)null,
                    Credit = row.InvCredit != null ? Convert.ToDecimal(row.InvCredit) : (decimal?)null,
                    CrDeb = row.InvCrDeb == "No" ? false : true,
                    Description = row.InvDescription,
                    LineNo = row.InvLineNo != null ? Convert.ToInt32(row.InvLineNo) : 0,
                    Price = row.InvPrice != null ? Convert.ToDecimal(row.InvPrice) : 0,
                    PriceChange = row.InvPriceChange != null ? Convert.ToDecimal(row.InvPriceChange) : (decimal?)null,
                    Qty = row.InvQty != null ? Convert.ToInt32(row.InvQty) : 0,
                });
            return InvoiceBData;
        }
        private OperationInvoiceViewModel InitOperationInvoiceViewModel(OperationInvoiceBData Data)
        {
            OperationInvoiceViewModel OperInvView = new OperationInvoiceViewModel();
            OperInvView.Rows = new List<OperationInvoiceGridViewModel>();
            OperInvView.InvBanks = new List<System.Web.WebPages.Html.SelectListItem>();
            OperInvView.InvSalesPerson = new List<System.Web.WebPages.Html.SelectListItem>();
            OperInvView.InvContactPerson = new List<System.Web.WebPages.Html.SelectListItem>();
            OperInvView.InvTypes = new List<System.Web.WebPages.Html.SelectListItem>();
            OperInvView.InvPaymentTerms = new List<System.Web.WebPages.Html.SelectListItem>();
            //type
            if (Data != null && Data.InvType != null)
                foreach (var type in Data.InvType)
                    OperInvView.InvTypes.Add(new System.Web.WebPages.Html.SelectListItem { Text = type.Value, Value = type.Key.ToString() });
            //Bank
            if (Data != null && Data.InvBanks != null)
                foreach (var bank in Data.InvBanks)
                    OperInvView.InvBanks.Add(new System.Web.WebPages.Html.SelectListItem { Text = bank.Value, Value = bank.Key.ToString() });
            //Sales Person
            if (Data != null && Data.InvSalesPerson != null)
                foreach (var sales in Data.InvSalesPerson)
                    OperInvView.InvSalesPerson.Add(new System.Web.WebPages.Html.SelectListItem { Text = sales.Value, Value = sales.Key.ToString() });
            //Contact Person
            if (Data != null && Data.ContactPerson != null)
                foreach (var Contact in Data.ContactPerson)
                    OperInvView.InvContactPerson.Add(new System.Web.WebPages.Html.SelectListItem { Text = Contact.Value, Value = Contact.Key.ToString() });
            //Payment terms
            if (Data != null && Data.InvPaymentTerms != null)
                foreach (var terms in Data.InvPaymentTerms)
                    OperInvView.InvPaymentTerms.Add(new System.Web.WebPages.Html.SelectListItem { Text = terms, Value = terms });
           
            var TotalCrd = Data.Rows.Sum(crd => crd.Credit);
            var TotalDeb = Data.Rows.Sum(crd => crd.Debit);
            OperInvView.InvTotalCredit = DoubleStringGeneratorF((double?)TotalCrd);
            OperInvView.InvTotalDebit = DoubleStringGeneratorF((double?)TotalDeb);
            OperInvView.InvTotalDeposit = DoubleStringGeneratorF((double?)Data.InvTotalDeposit);
            OperInvView.InvTotalRefund = DoubleStringGeneratorF((double?)Data.InvTotalRefund);
            OperInvView.InvAmountDue = DoubleStringGeneratorF((double?)(Convert.ToDecimal(TotalDeb) - Convert.ToDecimal(TotalCrd) - Convert.ToDecimal(Data.InvTotalDeposit)));
            OperInvView.InvGroupQuotaID = Data.InvGroupQuotaID != null ? Data.InvGroupQuotaID.ToString() : "";
            OperInvView.InvIsGroupGir = Data.InvIsGroupGir;
            OperInvView.InvoiceCustomerID = Data.InvoiceCustomerID;
            OperInvView.InvComments = Data.InvoiceComment;
            OperInvView.InvProfComments = Data.PerformaComment;
            OperInvView.InvCadUsdRate = Data.InvCadUsdRate.ToString();
            OperInvView.InvoiceRateChangeDate = Data.InvRateChangeDate != null ? Convert.ToDateTime(Data.InvRateChangeDate).ToString("dd/MMM/yy") : "";
            OperInvView.InvoiceGroupName = Data.InvoiceGroupName;
            OperInvView.InvoiceGroupCode = Data.InvoiceGroupCode;
            OperInvView.InvoiceCustomer = Data.InvoiceCustomer;
            OperInvView.InvoiceGroupID = Data.InvoiceGroupID;
            OperInvView.InvoiceArrivalDate = Data.InvoiceArrivalDate != null ? Convert.ToDateTime(Data.InvoiceArrivalDate).ToString("dd/MMM/yy") : "";
            OperInvView.InvoiceNo = Data.InvoiceDate != null ? Convert.ToDateTime(Data.InvoiceDate).ToString("yyMMdd") + "-" + Data.InvoiceNo.ToString() : Data.InvoiceNo.ToString();
            OperInvView.InvoiceDate = Data.InvoiceDate != null ? Convert.ToDateTime(Data.InvoiceDate).ToString("dd/MMM/yy") : "";
            OperInvView.InvDepositDue = Data.DepositDue != null ? Convert.ToDateTime(Data.DepositDue).ToString("dd/MMM/yy") : "";
            OperInvView.InvFinalPayment = Data.FinalPayment != null ? Convert.ToDateTime(Data.FinalPayment).ToString("dd/MMM/yy") : "";
            OperInvView.InvDepositM = Data.DepositM != null ? Convert.ToBoolean(Data.DepositM) : false;
            OperInvView.InvDepositAmt = (Data.DepositAmount != null || Data.DepositM != true) ? Convert.ToDecimal(Data.DepositAmount).ToString("F") : "0";
            OperInvView.SelectedInvSalesPerson = Data.SelectedInvSalesPerson.ToString();
            OperInvView.SelectedInvContactPerson = Data.SelectedContactPerson.ToString();
            OperInvView.InvProforma = Data.InvProforma != null ? Convert.ToBoolean(Data.InvProforma) : false;
            OperInvView.SelectedInvPaymentTerms = Data.SelectedInvPaymentTerms;
            OperInvView.SelectedInvBank = Data.SelectedInvBank.ToString();
            if (Data != null && Data.Rows != null)
                foreach (var row in Data.Rows)
                {
                    string VendID = row.VendorID == null ? "0" : row.VendorID.ToString();
                    OperInvView.Rows.Add(new OperationInvoiceGridViewModel
                    {
                        InvLineNo = row.LineNo.ToString(),
                        InvSelType = row.SelType,
                        InvSelTypeID = row.SelTypeID.ToString(),
                        InvQty = row.Qty.ToString(),
                        InvDescription = row.Description,
                        InvCrDeb = row.CrDeb != null ? Convert.ToBoolean(row.CrDeb) == true ? "Yes" : "No" : "No",
                        InvPrice = Math.Round(row.Price).ToString(),
                        InvPriceChange = row.PriceChange != null ? Math.Round(Convert.ToDecimal(row.PriceChange)).ToString() : "",
                        InvCredit = row.Credit != null ? Math.Round(Convert.ToDecimal(row.Credit)).ToString() : "",
                        InvDebit = row.Debit != null ? Math.Round(Convert.ToDecimal(row.Debit)).ToString() : "",
                        InvCurrency = row.Currency,
                        InvDeleteHtml = "<div style='text-align:center;'><button class='btn14 btn50 btnheight22 btn-danger' type='button' style='padding:0px;' onclick='RemoveInvoiceByLine(" + Data.InvoiceGroupID + "," + row.LineNo + "," + VendID + ")'>Delete</button></div>",
                    });
                }
            if (Data.Error.Message != null)
                OperInvView.OperInvMessageInfo = Data.Error.Message;
            return OperInvView;
        }
        private void ResetAllAttractionsProp(OperationAttractionsGridViewModel model)
        {
            model.AttractionsPageNumber = 1;
            // init Filters Remove
            model.IsRemoveAttractionsFilterDivShow = false;
            model.IsRemoveAttractionsCustomerCodeFilter = false;
            model.IsRemoveAttractionsGroupCodeFilter = false;
            model.IsRemoveAttractionsGroupNameFilter = false;
            model.IsRemoveAttractionsVendorNameFilter = false;
            model.IsRemoveAttractionsVendorCityFilter = false;
            model.IsRemoveAttractionsStatusFilter = false;
            model.IsRemoveAttractionsVendorTypeFilter = false;
            model.IsRemoveAttractionsRestaurantTypeFilter = false;
            // All View prop should be true
            model.ViewAttractionsIsGuideInvoice = true;
            model.ViewAttractionsGuideInvoicePrice = true;
            model.ViewAttractionsIsInvoice = true;
            model.ViewAttractionsInvoicePrice = true;
            model.ViewAttractionsOptionalHtml = true;
            model.ViewAttractionsGroupCode = true;
            model.ViewAttractionsConfHtml = true;
            model.ViewAttractionsGroupName = true;
            model.ViewAttractionsCustomer = true;
            model.ViewAttractionsPax = true;
            model.ViewAttractionsEmployee = true;
            model.ViewAttractionsEstNumberofPerson = true;
            model.ViewAttractionsSupplier = true;
            model.ViewAttractionsDifference = true;
            model.ViewAttractionsDone = true;
            model.ViewAttractionsDate = true;
            model.ViewAttractionsTime = true;
            model.ViewAttractionsCategory = true;
            model.ViewAttractionsType = true;
            model.ViewAttractionsOutstandingAmt = true;
            model.ViewAttractionsUnitRate = true;
            model.ViewAttractionsDeposit = true;
            model.ViewAttractionsDepositDate = true;
            model.ViewAttractionsContact = true;
            model.ViewAttractionsPhone = true;
            model.ViewAttractionsEmail = true;
            model.ViewAttractionsAddress = true;
            model.ViewAttractionsCity = true;
            model.ViewAttractionsState = true;
            model.ViewAttractionsTotalCost = true;
            model.ViewAttractionsTotalAmountPaid = true;
            model.ViewAttractionsFinalPayment = true;
            model.ViewAttractionsDepositAmountPaid = true;
            model.ViewAttractionsCreditCardChargeAmount = true;
            model.ViewAttractionsCreditCardMemo = true;
            model.ViewAttractionsDifferenceTotalPaid_TotalCharged = true;
            model.ViewAttractionsFirstPayment = true;
            model.ViewAttractionsSelectedFirstPaymentMethod = true;
            model.ViewAttractionsDateFirstPayment = true;
            model.ViewAttractionsSecondPayment = true;
            model.ViewAttractionsSelectedSecondPaymentMethod = true;
            model.ViewAttractionsDateSecondPayment = true;
            model.ViewAttractionsThirdPayment = true;
            model.ViewAttractionsSelectedThirdPaymentMethod = true;
            model.ViewAttractionsDateThirdPayment = true;
            model.ViewAttractionsStatus = true;
            model.ViewAttractionsRestService = true;
            model.ViewAttractionsCurrency = true;
            model.ViewAttractionsQuotaPrice = true;
            model.ViewAttractionsQuotaSupplier = true;
        }
        private void ResetAllMiscProp(OperationMiscGridViewModel model)
        {
            model.MiscPageNumber = 1;
            // init Filters Remove
            model.IsRemoveMiscFilterDivShow = false;
            model.IsRemoveMiscCustomerCodeFilter = false;
            model.IsRemoveMiscGroupCodeFilter = false;
            model.IsRemoveMiscGroupNameFilter = false;
            model.IsRemoveMiscVendorNameFilter = false;
            model.IsRemoveMiscVendorCityFilter = false;
            model.IsRemoveMiscStatusFilter = false;
            // All View prop should be true
            model.ViewMiscPlane = true;
            model.ViewMiscIsComp = true;
            model.ViewMiscGroupCode = true;
            model.ViewMiscConfHtml = true;
            model.ViewMiscGroupName = true;
            model.ViewMiscCustomer = true;
            model.ViewMiscEmployee = true;
            model.ViewMiscServiceDetail = true;
            model.ViewMiscPax = true;
            model.ViewMiscEstNumberofPerson = true;
            model.ViewMiscSupplier = true;
            model.ViewMiscDate = true;
            model.ViewMiscTime = true;
            model.ViewMiscUnitPrice = true;
            model.ViewMiscUnitPricePG = true;
            model.ViewMiscDiff = true;
            model.ViewMiscPGDiff = true;
            model.ViewMiscContact = true;
            model.ViewMiscPhone = true;
            model.ViewMiscEmail = true;
            model.ViewMiscAddress = true;
            model.ViewMiscCity = true;
            model.ViewMiscNotes = true;
            model.ViewMiscStatus = true;
            model.ViewMiscCurrency = true;
            model.ViewMiscTotalAmountPaid = true;
            model.ViewMiscTotalCost = true;
            model.ViewMiscOutstandingAmt = true;
            model.ViewMiscFirstPayment = true;
            model.ViewMiscSelectedFirstPaymentMethod = true;
            model.ViewMiscDateFirstPayment = true;
            model.ViewMiscSecondPayment = true;
            model.ViewMiscSelectedSecondPaymentMethod = true;
            model.ViewMiscDateSecondPayment = true;
            model.ViewMiscThirdPayment = true;
            model.ViewMiscSelectedThirdPaymentMethod = true;
            model.ViewMiscDateThirdPayment = true;
            model.ViewMiscQuotaPrice = true;
            model.ViewMiscQuotaPerGroupPrice = true;
            model.ViewMiscQuotaSupplier = true;
        }
        private void ResetAllTechProgProp(OperationTechProgGridViewModel model)
        {
            // init Filters Remove
            model.TechProgIsRemoveFilterDivShow = false;
            model.TechProgIsRemoveTypeFilter = false;
            //Hide show
            model.ViewTechProgDay = true;
            model.ViewTechProgPrn = true;
            model.ViewTechProgDate = true;
            model.ViewTechProgTime = true;
            model.ViewTechProgDetail = true;
            model.ViewTechProgDescription = true;
            model.ViewTechProgVia = true;
            model.ViewTechProgType = true;
            model.ViewTechProgVendorName = true;
            model.ViewTechProgVendorAddress = true;
            model.ViewTechProgVendorEmail = true;
            model.ViewTechProgGuideName = true;
            model.ViewTechProgGuidePhone = true;
            model.ViewTechProgCity = true;
            model.ViewTechProgArea = true;
        }
        private void ResetAllBusProp(OperationBusGridViewModel model)
        {
            model.BusPageNumber = 1;
            // init Filters Remove
            model.IsRemoveBusFilterDivShow = false;
            model.IsRemoveBusCustomerCodeFilter = false;
            model.IsRemoveBusGroupCodeFilter = false;
            model.IsRemoveBusGroupNameFilter = false;
            model.IsRemoveBusVendorNameFilter = false;
            model.IsRemoveBusStartCityFilter = false;
            model.IsRemoveBusEndCityFilter = false;
            model.IsRemoveBusStatusFilter = false;
            // All View prop should be true
            model.ViewBusIsInvoice = true;
            model.ViewBusInvoicePrice = true;
            model.ViewBusGroupCode = true;
            model.ViewBusGroupName = true;
            model.ViewBusCustomer = true;
            model.ViewBusPax = true;
            model.ViewBusEstNumberofPerson = true;
            model.ViewBusCost = true;
            model.ViewBusEmployee = true;
            model.ViewBusGuideTotalPaid = true;
            model.ViewBusBusTotalPaid = true;
            model.ViewBusGuideDifference = true;
            model.ViewBusGuideMiscDifference = true;
            model.ViewBusGuideStepOnDifference = true;
            model.ViewBusBusDifference = true;
            model.ViewBusStart = true;
            model.ViewBusConfHtml = true;
            model.ViewBusTime = true;
            model.ViewBusDateOfService = true;
            model.ViewBusStartCity = true;
            model.ViewBusEndCity = true;
            model.ViewBusBusCount = true;
            model.ViewBusBusSize = true;
            model.ViewBusServiceCode = true;
            model.ViewBusServiceDetail = true;
            model.ViewBusSupplier = true;
            model.ViewBusAirport = true;
            model.ViewBusStatus = true;
            model.ViewBusConfirmation = true;
            model.ViewBusOperations = true;
            model.ViewBusGuide = true;
            model.ViewBusGuideSalary = true;
            model.ViewBusGuideMisc = true;
            model.ViewBusGuideStepOn = true;
            model.ViewBusGuideSalaryPaid = true;
            model.ViewBusGuideAdditionalCharges = true;
            model.ViewBusGuideSalaryInvoicePaid = true;
            model.ViewBusBusTotalCost = true;
            model.ViewBusGuideTotalCost = true;
            model.ViewBusPrice = true;
            model.ViewBusBusCurrency = true;
            model.ViewBusQuotaBusPrice = true;
            model.ViewBusQuotaSupplier = true;
            model.ViewBusGuideCurrency = true;
            model.ViewBusQuotaGuideSalary = true;
            model.ViewBusQuotaGuideMisc = true;
            model.ViewBusQuotaGuideStepOn = true;
            model.ViewBusQuotaGuide = true;
            model.ViewBusFirstPayment = true;
            model.ViewBusSelectedFirstPaymentMethod = true;
            model.ViewBusDateFirstPayment = true;
            model.ViewBusDateFirstPayment = true;
            model.ViewBusSecondPayment = true;
            model.ViewBusSelectedSecondPaymentMethod = true;
            model.ViewBusDateSecondPayment = true;
            model.ViewBusThirdPayment = true;
            model.ViewBusSelectedThirdPaymentMethod = true;
            model.ViewBusDateThirdPayment = true;
            model.ViewBusGuideFirstPayment = true;
            model.ViewBusGuideSelectedFirstPaymentMethod = true;
            model.ViewBusGuideDateFirstPayment = true;
            model.ViewBusGuideSecondPayment = true;
            model.ViewBusGuideSelectedSecondPaymentMethod = true;
            model.ViewBusGuideDateSecondPayment = true;
            model.ViewBusGuideThirdPayment = true;
            model.ViewBusGuideSelectedThirdPaymentMethod = true;
            model.ViewBusGuideDateThirdPayment = true;
            model.ViewBusNotes = true;
        }
        private void ResetAllGroupCheckListProp(OperationGroupCheckListGridViewModel model)
        {
            model.GroupCheckListPageNumber = 1;
            model.IsRemoveGroupCheckListFilterDivShow = false;
            // All View prop should be true
            model.ViewGroupCheckListGroupCode = true;
            model.ViewGroupCheckListGroupName = true;
            model.ViewGroupCheckListCustomer = true;
            model.ViewGroupCheckListPax = true;
            model.ViewGroupCheckListIsGir = true;
            model.ViewGroupCheckListMonthOfArrival = true;
            model.ViewGroupCheckListHotelStatus = true;
            model.ViewGroupCheckListHotelNotes = true;
            model.ViewGroupCheckListBusGuideNotes = true;
            model.ViewGroupCheckListArrivalDate = true;
            model.ViewGroupCheckListArrivalCity = true;
            model.ViewGroupCheckListDepartureDate = true;
            model.ViewGroupCheckListDepartureCity = true;
        }
        private void ResetAllHotelProp(OperationHotelGridViewModel model)
        {
           model.HotelPageNumber = 1;
            // init Filters Remove
           model.IsRemoveFilterDivShow = false;
           model.IsRemoveCustomerCodeFilter = false;
           model.IsRemoveGroupCodeFilter = false;
           model.IsRemoveGroupNameFilter = false;
           model.IsRemoveVendorNameFilter = false;
           model.IsRemoveVendorCityFilter = false;
           model.IsRemoveStatusFilter = false;
           model.IsRemoveGroupStatusFilter = false;
           model.IsRemoveArrivalCityFilter = false;
           model.IsRemoveEstNumberRoomFilter = false;
           model.IsRemoveDayofArrivalFilter = false;
           model.IsRemoveMonthofArrivalFilter = false;
            // All View prop should be true
            model.ViewGroupCode = true;
            model.ViewCustomerCode = true;
            model.ViewDetails = true;
            model.ViewGroupStatus = true;
            model.ViewGroupName = true;
            model.ViewArrivalDate = true;
            model.ViewDepartureDate = true;
            model.ViewRoomCount = true;
            model.ViewEmployee = true;
            model.ViewVendorStatus = true;
            model.ViewVendorName = true;
            model.ViewVendorCity = true;
            model.ViewVendorAddress = true;
            model.ViewVendorPhone = true;
            model.ViewPax = true;
            model.ViewArrivalCity = true;
            //model.ViewDepartureCity = true;
            model.ViewNights = true;
            model.ViewFileCompDays = true;
            model.ViewTotalCost = true;
            model.ViewBreakDownTotal = true;
            model.ViewOutstandingBalance = true;
            model.ViewComAmount = true;
            model.ViewComDifference = true;
            model.ViewCurrency = true;
            model.ViewTotalInvoice = true;
            model.ViewTotalPaid = true;
            model.ViewFirstPayment = true;
            model.ViewFirstPaymentMethod = true;
            model.ViewDateFirstPayment = true;
            model.ViewSecondPayment = true;
            model.ViewSecondPaymentMethod = true;
            model.ViewDateSecondPayment = true;
            model.ViewThirdPayment = true;
            model.ViewThirdPaymentMethod = true;
            model.ViewDateThirdPayment = true;
            model.ViewRefundReceivedHotel = true;
            model.ViewTotalCharged = true;
            model.ViewAuthDiff = true;
            model.ViewAccountingMemo = true;
            model.ViewCommissionStatus = true;
            model.ViewCommissionPrc = true;
            model.ViewCommissionReceived = true;
            model.ViewCommissionDateReceived = true;
            model.ViewCheckNumber = true;
            model.ViewCheckAmount = true;
            model.ViewSGLCount = true;
            model.ViewSGLAmount = true;
            model.ViewDBLCount = true;
            model.ViewDBLAmount = true;
            model.ViewTWNCount = true;
            model.ViewTWNAmount = true;
            model.ViewTRPLCount = true;
            model.ViewTRPLAmount = true;
            model.ViewQUDCount = true;
            model.ViewQUDAmount = true;
            model.ViewGuideCount = true;
            model.ViewGuideAmount = true;
            model.ViewDriverCount = true;
            model.ViewDriverAmount = true;
            model.ViewTaxPrc = true;
            model.ViewOccTax = true;
            model.ViewBag = true;
            model.ViewCBF = true;
            model.ViewABF = true;
            model.ViewLunch = true;
            model.ViewDinner = true;
            model.ViewVConfHtml = true;
            model.ViewComp = true;
            model.ViewExtraCost = true;
            model.ViewXLTDate = true;
            model.ViewDateFileReceived = true;
            model.ViewDateFileCompleted = true;
            model.ViewDayOfArrival = true;
            model.ViewMonthOfArrival = true;
            model.ViewClientBookingCode = true;
            model.ViewCheckInDate = true;
            model.ViewCheckOutDate = true;
            model.ViewEstimatedNumberRooms = true;
            model.ViewEstimatedNumberPax = true;
            model.ViewQuotaRoom = true;
            model.ViewQuotaRoomDiff = true;
            model.ViewQuotaTax = true;
            model.ViewQuotaOccTax = true;
            model.ViewQuotaBrk = true;
            model.ViewQuotaLg = true;
            model.ViewQuotaNight = true;
            model.ViewQuotaVendorName = true;
            model.ViewQuotaNote = true;
            model.ViewConfirmed = true;
            model.ViewVendorEmail = true;
            model.ViewVendorContactName = true;
            model.ViewVendorTech = true;
            model.ViewVendorNote = true;
        }
        private void ResetAllRoomsProp(OperationRoomGridViewModel model)
        {
            model.RoomPageNumber = 1;
            // init Filters Remove
            model.RoomIsRemoveFilterDivShow = false;
            model.RoomIsRemoveCustomerCodeFilter = false;
            model.RoomIsRemoveRoomTypeFilter = false;
            model.RoomIsRemoveRoomTitleFilter = false;
            //View prop
            model.ViewRoomGroupName = false;
            model.ViewRoomGroupCode = false;
            model.ViewRoomCustomer = true;
            model.ViewRoomPax = true;
            model.ViewRoomType = true;
            model.ViewRoomPaxRoom = false;
            model.ViewRoomTitle = true;
            model.ViewRoomNames = true;
            model.ViewRoomFullBoard = true;
            model.ViewRoomFullBoardCount = true;
            model.ViewRoomTitle = true;
            model.ViewRoomNotes = true; 
        }
        private OperationHotelGridViewModel LoadOperationHotelGridDatainit(OperationHotelGridViewModel model)
        {
            OprManager = new OperationManager();
            var HotelData = OprManager.LoadOperationHotels(model.HotelPageNumber, UserRegions, User.Identity.Name);
            OperationHotelGridViewModel OperHotelGridView = new OperationHotelGridViewModel();
            InitHotelGridViewData(HotelData, OperHotelGridView);
            OperationHotelInitModelState(OperHotelGridView, model, (double?)HotelData.Count);
            if (model.HotelPageNumber > 1)
            {
                OperHotelGridView.IsCanPrev = true;
            }
            else
            {
                OperHotelGridView.IsCanPrev = false;
            }
            if (model.HotelPageNumber < OperHotelGridView.CountCheck)
            {
                OperHotelGridView.IsCanNext = true;
            }
            else
            {
                OperHotelGridView.IsCanNext = false;
            }
            return OperHotelGridView;
        }
        private OperationRoomGridViewModel LoadOperationRoomGridDatainit(OperationRoomGridViewModel model)
        {      
            OprManager = new OperationManager();
            var RoomData = OprManager.LoadOperationRooms(model.RoomPageNumber,UserRegions);    
            OperationRoomGridViewModel OperRoomGridView = new OperationRoomGridViewModel();
            
            InitRoomGridViewData(RoomData, OperRoomGridView);
            OperationRoomInitModelState(OperRoomGridView, model);
            return OperRoomGridView;
        }
        private OperationAttractionsGridViewModel LoadOperationAttractionsGridDatainit(OperationAttractionsGridViewModel model)
        {
            OprManager = new OperationManager();
            var AttractionsData = OprManager.LoadOperationAttractions(model.AttractionsPageNumber, UserRegions, User.Identity.Name);
            OperationAttractionsGridViewModel OperAttractionsGridView = new OperationAttractionsGridViewModel();
            InitAttractionsGridViewData(AttractionsData, OperAttractionsGridView);
            OperationAttractionsInitModelState(OperAttractionsGridView, model, (double?)AttractionsData.AttrCount);
            if (model.AttractionsPageNumber > 1)
            {
                OperAttractionsGridView.IsAttractionsCanPrev = true;
            }
            else
            {
                OperAttractionsGridView.IsAttractionsCanPrev = false;
            }
            if (model.AttractionsPageNumber < OperAttractionsGridView.AttractionsCountCheck)
            {
                OperAttractionsGridView.IsAttractionsCanNext = true;
            }
            else
            {
                OperAttractionsGridView.IsAttractionsCanNext = false;
            }
            return OperAttractionsGridView;
        }
        private OperationMiscGridViewModel LoadOperationMiscGridDatainit(OperationMiscGridViewModel model)
        {
            OprManager = new OperationManager();
            var MiscData = OprManager.LoadOperationMisc(model.MiscPageNumber, UserRegions, User.Identity.Name);
            OperationMiscGridViewModel OperMiscGridView = new OperationMiscGridViewModel();
            InitMiscGridViewData(MiscData, OperMiscGridView);
            OperationMiscInitModelState(OperMiscGridView, model, (double?)MiscData.MiscCount);
            if (model.MiscPageNumber > 1)
            {
                OperMiscGridView.IsMiscCanPrev = true;
            }
            else
            {
                OperMiscGridView.IsMiscCanPrev = false;
            }
            if (model.MiscPageNumber < OperMiscGridView.MiscCountCheck)
            {
                OperMiscGridView.IsMiscCanNext = true;
            }
            else
            {
                OperMiscGridView.IsMiscCanNext = false;
            }
            return OperMiscGridView;
        }
        private OperationBusGridViewModel LoadOperationBusGridDatainit(OperationBusGridViewModel model)
        {
            OprManager = new OperationManager();
            var BusData = OprManager.LoadOperationBus(model.BusPageNumber, UserRegions, User.Identity.Name);
            OperationBusGridViewModel OperBusGridView = new OperationBusGridViewModel();
            InitBusGridViewData(BusData, OperBusGridView);
            OperationBusInitModelState(OperBusGridView, model, (double?)BusData.BusCount);
            if (model.BusPageNumber > 1)
            {
                OperBusGridView.IsBusCanPrev = true;
            }
            else
            {
                OperBusGridView.IsBusCanPrev = false;
            }
            if (OperBusGridView.BusPageNumber < OperBusGridView.BusCountCheck)
            {
                OperBusGridView.IsBusCanNext = true;
            }
            else
            {
                OperBusGridView.IsBusCanNext = false;
            }
            return OperBusGridView;
        }
        private OperationTechProgGridViewModel LoadOperationTechProgGridDatainit(OperationTechProgGridViewModel model)
        {
            OprManager = new OperationManager();
            var TechProgFilterBData = OperationTechProgGridFilterBDatainit(model);
            var TechProgData = OprManager.LoadOperationTechProg(model.TechProgSearchGroupCode, TechProgFilterBData);
            OperationTechProgGridViewModel OperTechProgGridView = new OperationTechProgGridViewModel();
            InitTechProgGridViewData(TechProgData, OperTechProgGridView);
            OperationTechProgInitModelState(OperTechProgGridView, model);

            return OperTechProgGridView;
        }
        private OperationTechProgGridViewModel ValidateOperationTechProgGridDatainit(string GroupCode)
        {
            OprManager = new OperationManager();
            var TechProgFilterBData = new OperationTechProgFilterBData();
            var TechProgData = OprManager.ValidateOperationTechProg(GroupCode, TechProgFilterBData);
            OperationTechProgGridViewModel OperTechProgGridView = new OperationTechProgGridViewModel();
            InitTechProgGridViewData(TechProgData, OperTechProgGridView);
            return OperTechProgGridView;
        }
        private OperationGroupCheckListGridViewModel LoadOperationGroupCheckListGridDatainit(OperationGroupCheckListGridViewModel model, string UserName)
        {
            OprManager = new OperationManager();
            var GroupCheckListData = OprManager.LoadOperationGroupCheckList(model.GroupCheckListPageNumber, UserRegions, UserName);
            OperationGroupCheckListGridViewModel OperGroupCheckListGridView = new OperationGroupCheckListGridViewModel();
            InitGroupCheckListGridViewData(GroupCheckListData, OperGroupCheckListGridView);
            OperationGroupCheckListInitModelState(OperGroupCheckListGridView, model);
            if (GroupCheckListData.Rows.Count != model.GroupCheckListPageNumber * OperationGroupCheckListGridBData.TakeCount)
            {
                OperGroupCheckListGridView.IsGroupCheckListCanView = false;
            }
            else
            {
                OperGroupCheckListGridView.IsGroupCheckListCanView = true;
            }
            return OperGroupCheckListGridView;
        }
        private OperationRoomGridViewModel SearchOperationRoomGridDatainit(OperationRoomGridViewModel model)
        {
            if (model.RoomPageNumber == 0)
                ResetAllRoomsProp(model);
            OperationRoomGridViewModel OperRoomGridView = new OperationRoomGridViewModel();
            OprManager = new OperationManager();
            OperationRoomGridBData RoomData = new OperationRoomGridBData();
            if (model.RoomGroupNameTxt != null && model.RoomGroupCodeTxt != null && model.RoomCustomerTxt != null)
            {
                OperationRoomSearchBData Data = new OperationRoomSearchBData { GroupName = model.RoomGroupNameTxt, GroupCode = model.RoomGroupCodeTxt, CustomerOrgName = model.RoomCustomerTxt };
                RoomData = OprManager.LoadOperationRooms(model.RoomPageNumber, Data, UserRegions);
            }
            // url open
            if (model.RoomGroupCodeTxt != null)
            {
                OperationRoomSearchBData Data = new OperationRoomSearchBData { GroupName = model.RoomGroupNameTxt, GroupCode = model.RoomGroupCodeTxt, CustomerOrgName = model.RoomCustomerTxt };
                RoomData = OprManager.LoadOperationRooms(model.RoomPageNumber, Data, UserRegions);
                model.RoomGroupIDTxt = RoomData.GroupID;
                model.RoomGroupQuotaID = RoomData.QuotaID.ToString();
            }
            
            InitRoomGridViewData(RoomData, OperRoomGridView);
            OperationRoomInitModelState(OperRoomGridView, model);

            return OperRoomGridView;
        }
        private OperationHotelGridViewModel OperationHotelGridFilterDatainit(OperationHotelGridViewModel model)
        {
            OprManager = new OperationManager();
            var HotelFilterBData = OperationHotelGridFilterBDatainit(model);
            var HotelGridBData = InitOperationSearchBData(model);
            var HotelData = OprManager.OperationHotelsFilter(HotelGridBData, HotelFilterBData, model.HotelPageNumber, UserRegions, User.Identity.Name);
            OperationHotelGridViewModel OperHotelGridView = new OperationHotelGridViewModel();
            InitHotelGridViewData(HotelData, OperHotelGridView);
            OperationHotelInitModelState(OperHotelGridView, model, (double?)HotelData.Count);

            return OperHotelGridView;
        }
        private OperationHotelGridViewModel SearchOperationHotelGridDatainit(OperationHotelGridViewModel model)
        {
            OprManager = new OperationManager();
            var HotelFilterBData = OperationHotelGridFilterBDatainit(model);
            var HotelGridBData = InitOperationSearchBData(model);
            var HotelData = OprManager.SearchOperationHotels(HotelGridBData, HotelFilterBData, model.HotelPageNumber, UserRegions, User.Identity.Name);
            OperationHotelGridViewModel OperHotelGridView = new OperationHotelGridViewModel();
            InitHotelGridViewData(HotelData, OperHotelGridView);
            OperationHotelInitModelState(OperHotelGridView, model, (double?)HotelData.Count);

            return OperHotelGridView;
        }
        private OperationRoomGridViewModel OperationRoomGridFilterDatainit(OperationRoomGridViewModel model)
        {
            OprManager = new OperationManager();
            var RoomFilterBData = OperationRoomGridFilterBDatainit(model);
            var RoomData = OprManager.OperationRoomsFilter(RoomFilterBData, model.RoomPageNumber, UserRegions);
            OperationRoomGridViewModel OperRoomGridView = new OperationRoomGridViewModel();
            InitRoomGridViewData(RoomData, OperRoomGridView);
            OperationRoomInitModelState(OperRoomGridView, model);

            return OperRoomGridView;
        }
        private OperationRoomGridViewModel OperationRoomGridRemoveDatainit(OperationRoomGridViewModel model)
        {
            OprManager = new OperationManager();
            var RoomFilterBData = OperationRoomGridFilterBDatainit(model);
            var RoomData = OprManager.OperationRoomsRemove(RoomFilterBData, model.RemoveGroupID, model.RemoveLineNo, model.RoomPageNumber, UserRegions);
            OperationRoomGridViewModel OperRoomGridView = new OperationRoomGridViewModel();
            if (RoomData.Error.Message != null)
                OperRoomGridView.OperRoomMessageInfo = RoomData.Error.Message;
            InitRoomGridViewData(RoomData, OperRoomGridView);
            OperationRoomInitModelState(OperRoomGridView, model);

            return OperRoomGridView;
        }
        private OperationAttractionsGridViewModel OperationAttractionsGridFilterDatainit(OperationAttractionsGridViewModel model)
        {
            OprManager = new OperationManager();
            var AttractionsFilterBData = OperationAttractionsGridFilterBDatainit(model);
            var AttractionsGridBData = InitOperationSearchAttractionsBData(model);
            var AttractionsData = OprManager.OperationAttractionsFilter(AttractionsGridBData, AttractionsFilterBData, model.AttractionsPageNumber, UserRegions, User.Identity.Name);
            OperationAttractionsGridViewModel OperAttractionsGridView = new OperationAttractionsGridViewModel();
            InitAttractionsGridViewData(AttractionsData, OperAttractionsGridView);
            OperationAttractionsInitModelState(OperAttractionsGridView, model, (double?)AttractionsData.AttrCount);
            return OperAttractionsGridView;
        }
        private OperationAttractionsGridViewModel SearchOperationAttractionsGridDatainit(OperationAttractionsGridViewModel model)
        {
            OprManager = new OperationManager();
            var AttractionsFilterBData = OperationAttractionsGridFilterBDatainit(model);
            var AttractionsGridBData = InitOperationSearchAttractionsBData(model);
            var AttractionsData = OprManager.SearchOperationAttractions(AttractionsGridBData, AttractionsFilterBData, model.AttractionsPageNumber, UserRegions, User.Identity.Name);
            OperationAttractionsGridViewModel OperAttractionsGridView = new OperationAttractionsGridViewModel();
            InitAttractionsGridViewData(AttractionsData, OperAttractionsGridView);
            OperationAttractionsInitModelState(OperAttractionsGridView, model, (double?)AttractionsData.AttrCount);

            return OperAttractionsGridView;
        }
        private OperationMiscGridViewModel OperationMiscGridFilterDatainit(OperationMiscGridViewModel model)
        {
            OprManager = new OperationManager();
            var MiscFilterBData = OperationMiscGridFilterBDatainit(model);
            var MiscGridBData = InitOperationSearchMiscBData(model);
            var MiscData = OprManager.SearchOperationMisc(MiscGridBData, MiscFilterBData, model.MiscPageNumber, UserRegions, User.Identity.Name);
            OperationMiscGridViewModel OperMiscGridView = new OperationMiscGridViewModel();
            InitMiscGridViewData(MiscData, OperMiscGridView);
            OperationMiscInitModelState(OperMiscGridView, model, (double?)MiscData.MiscCount);

            return OperMiscGridView;
        }
        private OperationMiscGridViewModel SearchOperationMiscGridDatainit(OperationMiscGridViewModel model)
        {
            OprManager = new OperationManager();
            var MiscFilterBData = OperationMiscGridFilterBDatainit(model);
            var MiscGridBData = InitOperationSearchMiscBData(model);
            var MiscData = OprManager.SearchOperationMisc(MiscGridBData, MiscFilterBData, model.MiscPageNumber, UserRegions, User.Identity.Name);
            OperationMiscGridViewModel OperMiscGridView = new OperationMiscGridViewModel();
            InitMiscGridViewData(MiscData, OperMiscGridView);
            OperationMiscInitModelState(OperMiscGridView, model, (double?)MiscData.MiscCount);

            return OperMiscGridView;
        }
        private OperationBusGridViewModel OperationBusGridFilterDatainit(OperationBusGridViewModel model)
        {
            OprManager = new OperationManager();
            var BusFilterBData = OperationBusGridFilterBDatainit(model);
            var BusGridBData = InitOperationSearchBusBData(model);
            var BusData = OprManager.OperationBusFilter(BusGridBData, BusFilterBData, model.BusPageNumber, UserRegions, User.Identity.Name);
            OperationBusGridViewModel OperBusGridView = new OperationBusGridViewModel();
            InitBusGridViewData(BusData, OperBusGridView);
            OperationBusInitModelState(OperBusGridView, model, (double?)BusData.BusCount);

            return OperBusGridView;
        }
        private OperationBusGridViewModel SearchOperationBusGridDatainit(OperationBusGridViewModel model)
        {
            OprManager = new OperationManager();
            var BusFilterBData = OperationBusGridFilterBDatainit(model);
            var BusGridBData = InitOperationSearchBusBData(model);
            var BusData = OprManager.SearchOperationBus(BusGridBData, BusFilterBData, model.BusPageNumber, UserRegions, User.Identity.Name);
            OperationBusGridViewModel OperBusGridView = new OperationBusGridViewModel();
            InitBusGridViewData(BusData, OperBusGridView);
            OperationBusInitModelState(OperBusGridView, model, (double?)BusData.BusCount);

            return OperBusGridView;
        }
        private OperationGroupCheckListGridViewModel OperationGroupCheckListGridFilterDatainit(OperationGroupCheckListGridViewModel model)
        {
            OprManager = new OperationManager();
            var GroupCheckListFilterBData = OperationGroupCheckListGridFilterBDatainit(model);
            var GroupCheckListGridBData = InitOperationSearchGroupCheckListBData(model);
            var GroupCheckListData = OprManager.OperationGroupCheckListFilter(GroupCheckListGridBData, GroupCheckListFilterBData, model.GroupCheckListPageNumber, UserRegions, User.Identity.Name);
            OperationGroupCheckListGridViewModel OperGroupCheckListGridView = new OperationGroupCheckListGridViewModel();
            InitGroupCheckListGridViewData(GroupCheckListData, OperGroupCheckListGridView);
            OperationGroupCheckListInitModelState(OperGroupCheckListGridView, model);

            return OperGroupCheckListGridView;
        }
        private OperationGroupCheckListGridViewModel SearchOperationGroupCheckListGridDatainit(OperationGroupCheckListGridViewModel model)
        {
            OprManager = new OperationManager();
            var GroupCheckListFilterBData = OperationGroupCheckListGridFilterBDatainit(model);
            var GroupCheckListGridBData = InitOperationSearchGroupCheckListBData(model);
            var GroupCheckListData = OprManager.SearchOperationGroupCheckList(GroupCheckListGridBData, GroupCheckListFilterBData, model.GroupCheckListPageNumber, UserRegions, User.Identity.Name);
            OperationGroupCheckListGridViewModel OperGroupCheckListGridView = new OperationGroupCheckListGridViewModel();
            InitGroupCheckListGridViewData(GroupCheckListData, OperGroupCheckListGridView);
            OperationGroupCheckListInitModelState(OperGroupCheckListGridView, model);

            return OperGroupCheckListGridView;
        }
        private OperationTechProgGridViewModel SearchOperationTechProgGridDatainit(OperationTechProgGridViewModel model)
        {
            OprManager = new OperationManager();
            var TechProgFilterBData = OperationTechProgGridFilterBDatainit(model);
            var TechProgData = OprManager.LoadOperationTechProg(model.TechProgSearchGroupCode, TechProgFilterBData);
            OperationTechProgGridViewModel OperTechProgGridView = new OperationTechProgGridViewModel();
            InitTechProgGridViewData(TechProgData, OperTechProgGridView);
            OperationTechProgInitModelState(OperTechProgGridView, model);

            return OperTechProgGridView;
        }
        private OperationTechProgFilterBData OperationTechProgGridFilterBDatainit(OperationTechProgGridViewModel model)
        {
            var TechProgFilterBData = new OperationTechProgFilterBData();
            
            // filter Type
            if (model.SelectedTechProgFilterType != null && !(model.TechProgIsRemoveTypeFilter))
            {
                TechProgFilterBData.FilterTechProgTypeVal = new List<string>();
                foreach (var Type in model.SelectedTechProgFilterType)
                    TechProgFilterBData.FilterTechProgTypeVal.Add(Type);
            }

            return TechProgFilterBData;
        }
        private OperationRoomGridViewModel OperationRoomGridSaveDatainit(OperationRoomGridViewModel model)
        {
            OprManager = new OperationManager();
            var RoomGridBData = OperationRoomGridSaveBDatainit(model);
            var RoomFilterBData = OperationRoomGridFilterBDatainit(model);
            var RoomData = OprManager.OperationRoomsSave(RoomGridBData, RoomFilterBData, model.RoomPageNumber, UserRegions);
            OperationRoomGridViewModel OperRoomGridView = new OperationRoomGridViewModel();
            if (RoomData.Error.Message != null)
                OperRoomGridView.OperRoomMessageInfo = RoomData.Error.Message;
            InitRoomGridViewData(RoomData, OperRoomGridView);
            OperationRoomInitModelState(OperRoomGridView, model);

            return OperRoomGridView;
        }
        private OperationHotelGridViewModel OperationHotelGridSaveDatainit(OperationHotelGridViewModel model)
        {
            OprManager = new OperationManager();
            var HotelGridBData = OperationHotelGridSaveBDatainit(model);
            var HotelFilterBData = OperationHotelGridFilterBDatainit(model);
            var HotelData = OprManager.OperationHotelSave(HotelGridBData, HotelFilterBData, model.HotelPageNumber, UserRegions, User.Identity.Name);
            OperationHotelGridViewModel OperHotelGridView = new OperationHotelGridViewModel();
            InitHotelGridViewData(HotelData, OperHotelGridView);
            OperationHotelInitModelState(OperHotelGridView, model, (double?)HotelData.Count);

            return OperHotelGridView;
        }
        private OperationAttractionsGridViewModel OperationAttractionsGridSaveDatainit(OperationAttractionsGridViewModel model)
        {
            OprManager = new OperationManager();
            var AttractionsGridBData = OperationAttractionsGridSaveBDatainit(model);
            var AttractionsFilterBData = OperationAttractionsGridFilterBDatainit(model);
            var AttractionsData = OprManager.OperationAttractionsSave(AttractionsGridBData, AttractionsFilterBData, model.AttractionsPageNumber, UserRegions, User.Identity.Name);
            OperationAttractionsGridViewModel OperAttractionsGridView = new OperationAttractionsGridViewModel();
            InitAttractionsGridViewData(AttractionsData, OperAttractionsGridView);
            OperationAttractionsInitModelState(OperAttractionsGridView, model, (double?)AttractionsData.AttrCount);
            return OperAttractionsGridView;
        }
        private OperationMiscGridViewModel OperationMiscGridSaveDatainit(OperationMiscGridViewModel model)
        {
            OprManager = new OperationManager();
            var MiscGridBData = OperationMiscGridSaveBDatainit(model);
            var MiscFilterBData = OperationMiscGridFilterBDatainit(model);
            var MiscData = OprManager.OperationMiscSave(MiscGridBData, MiscFilterBData, model.MiscPageNumber, UserRegions, User.Identity.Name);
            OperationMiscGridViewModel OperMiscGridView = new OperationMiscGridViewModel();
            InitMiscGridViewData(MiscData, OperMiscGridView);
            OperationMiscInitModelState(OperMiscGridView, model, (double?)MiscData.MiscCount);

            return OperMiscGridView;
        }
        private OperationBusGridViewModel OperationBusGridSaveDatainit(OperationBusGridViewModel model)
        {
            OprManager = new OperationManager();
            var BusGridBData = OperationBusGridSaveBDatainit(model);
            var BusFilterBData = OperationBusGridFilterBDatainit(model);
            var BusData = OprManager.OperationBusSave(BusGridBData, BusFilterBData, model.BusPageNumber, UserRegions, User.Identity.Name);
            OperationBusGridViewModel OperBusGridView = new OperationBusGridViewModel();
            InitBusGridViewData(BusData, OperBusGridView);
            OperationBusInitModelState(OperBusGridView, model, (double?)BusData.BusCount);
            return OperBusGridView;
        }
        private OperationTechProgGridViewModel OperationTechProgGridSaveDatainit(OperationTechProgGridViewModel model)
        {
            OprManager = new OperationManager();
            var TechProgFilterBData = OperationTechProgGridFilterBDatainit(model);
            var TechProgGridBData = OperationTechProgGridSaveBDatainit(model);
            var TechProgData = OprManager.OperationTechProgSave(TechProgGridBData, TechProgFilterBData);
            OperationTechProgGridViewModel OperTechProgGridView = new OperationTechProgGridViewModel();
            InitTechProgGridViewData(TechProgData, OperTechProgGridView);
            OperationTechProgInitModelState(OperTechProgGridView, model);

            return OperTechProgGridView;
        }
        private OperationHotelGridBData InitOperationSearchBData(OperationHotelGridViewModel model)
        {
            OperationHotelGridBData Data = new OperationHotelGridBData()
            {
                SearchCheckInFromDate = model.SearchCheckInFromDate != null && model.SearchCheckInFromDate.Length>0?Convert.ToDateTime(model.SearchCheckInFromDate):(DateTime?)null,
                SearchCheckInToDate = model.SearchCheckInToDate != null && model.SearchCheckInToDate.Length>0?Convert.ToDateTime(model.SearchCheckInToDate):(DateTime?)null,
                SearchCheckOutFromDate = model.SearchCheckOutFromDate != null && model.SearchCheckOutFromDate.Length>0?Convert.ToDateTime(model.SearchCheckOutFromDate):(DateTime?)null,
                SearchCheckOutToDate = model.SearchCheckOutToDate != null && model.SearchCheckOutToDate.Length>0?Convert.ToDateTime(model.SearchCheckOutToDate):(DateTime?)null,
                SearchCustomer = model.SearchCustomer,
                SearchFlightNo = model.SearchFlightNo,
                SearchEmployeeID = model.SearchEmployeeID,
                SearchGroupCode = model.SearchGroupCode,
                SearchGroupName = model.SearchGroupName,
                SearchVendorName = model.SearchVendorName,
                SelectedSearchArrivalCity = model.SelectedSearchArrivalCity,
                SelectedSearchDepartureCity = model.SelectedSearchDepartureCity,
                SelectedSearchNationality = model.SelectedSearchNationality != null?Convert.ToInt32(model.SelectedSearchNationality):(int?)null,
                SelectedSearchStatus = model.SelectedSearchStatus != null?Convert.ToInt32(model.SelectedSearchStatus):(int?)null,
            };
            return Data;
        }
        private OperationHotelFilterBData  OperationHotelGridFilterBDatainit(OperationHotelGridViewModel model)
        {
            var HotelFilterBData = new OperationHotelFilterBData();
            // filter Group status
            if (model.SelectedFilterGroupStatus != null && !(model.IsRemoveGroupStatusFilter))
            {
                HotelFilterBData.FilterGroupStatusVal = new List<int?>();
                foreach (var sts in model.SelectedFilterGroupStatus)
                    HotelFilterBData.FilterGroupStatusVal.Add(Convert.ToInt32(sts));
            }
            // filter status
            if (model.SelectedFilterStatus != null && !(model.IsRemoveStatusFilter))
            {
                HotelFilterBData.FilterStatusVal = new List<int?>();
                foreach (var sts in model.SelectedFilterStatus)
                    HotelFilterBData.FilterStatusVal.Add(Convert.ToInt32(sts));
            }
            // filter Day of Arrival
            if (model.SelectedFilterDayofArrival != null && !(model.IsRemoveDayofArrivalFilter))
            {
                HotelFilterBData.FilterDayofArrivalVal = new List<int>();
                foreach (var dayofarrival in model.SelectedFilterDayofArrival)
                    HotelFilterBData.FilterDayofArrivalVal.Add(Convert.ToInt32(dayofarrival));
            }
            // filter Month of Arrival
            if (model.SelectedFilterMonthofArrival != null && !(model.IsRemoveMonthofArrivalFilter))
            {
                HotelFilterBData.FilterMonthofArrivalVal = new List<int>();
                foreach (var Monthofarrival in model.SelectedFilterMonthofArrival)
                    HotelFilterBData.FilterMonthofArrivalVal.Add(Convert.ToInt32(Monthofarrival));
            }
            // filter Arrival City
            if (model.SelectedFilterArrivalCity != null && !(model.IsRemoveArrivalCityFilter))
            {
                HotelFilterBData.FilterArrivalCityVal = new List<string>();
                foreach (var city in model.SelectedFilterArrivalCity)
                    HotelFilterBData.FilterArrivalCityVal.Add(city);
            }
            // filter Estimated Number Rooms
            if (model.SelectedFilterEstNumberRoom != null && !(model.IsRemoveEstNumberRoomFilter))
            {
                HotelFilterBData.FilterEstimatedRoomNumberVal = new List<int>();
                foreach (var estnumroom in model.SelectedFilterEstNumberRoom)
                    HotelFilterBData.FilterEstimatedRoomNumberVal.Add(Convert.ToInt16(estnumroom));
            }
            // filter Group Code
            if (model.SelectedFilterGroupCode != null && !(model.IsRemoveGroupCodeFilter))
            {
                HotelFilterBData.FilterGroupCodeVal = new List<int?>();
                foreach (var GroupCode in model.SelectedFilterGroupCode)
                    HotelFilterBData.FilterGroupCodeVal.Add(Convert.ToInt32(GroupCode));
            }
            // filter Group Name
            if (model.SelectedFilterGroupName != null && !(model.IsRemoveGroupNameFilter))
            {
                HotelFilterBData.FilterGroupNameVal = new List<int?>();
                foreach (var GroupName in model.SelectedFilterGroupName)
                    HotelFilterBData.FilterGroupNameVal.Add(Convert.ToInt32(GroupName));
            }
            // filter Customer
            if (model.SelectedFilterCustomerCode != null && !(model.IsRemoveCustomerCodeFilter))
            {
                HotelFilterBData.FilterCustomerCodeVal = new List<int?>();
                foreach (var cust in model.SelectedFilterCustomerCode)
                    HotelFilterBData.FilterCustomerCodeVal.Add(Convert.ToInt32(cust));
            }
            // filter Vendor Name
            if (model.SelectedFilterVendorName != null && !(model.IsRemoveVendorNameFilter))
            {
                HotelFilterBData.FilterVendorNameVal = new List<int?>();
                foreach (var vndname in model.SelectedFilterVendorName)
                    HotelFilterBData.FilterVendorNameVal.Add(Convert.ToInt32(vndname));
            }
            // filter Vendor City
            if (model.SelectedFilterVendorCity != null && !(model.IsRemoveVendorCityFilter))
            {
                HotelFilterBData.FilterVendorCityVal = new List<string>();
                foreach (var vndCity in model.SelectedFilterVendorCity)
                    HotelFilterBData.FilterVendorCityVal.Add(vndCity);
            }
            return HotelFilterBData;
        }
        private OperationRoomFilterBData OperationRoomGridFilterBDatainit(OperationRoomGridViewModel model)
        {
            var RoomFilterBData = new OperationRoomFilterBData();
            // filter customer
            if (model.SelectedRoomFilterCustomer != null && !(model.RoomIsRemoveCustomerCodeFilter))
            {
                RoomFilterBData.FilterRoomCustomerVal = new List<int>();
                foreach (var cust in model.SelectedRoomFilterCustomer)
                    RoomFilterBData.FilterRoomCustomerVal.Add(Convert.ToInt32(cust));
            }
            // filter Room Type
            if (model.SelectedRoomFilterRoomType != null && !(model.RoomIsRemoveRoomTypeFilter))
            {
                RoomFilterBData.FilterRoomTypeVal = new List<int>();
                foreach (var type in model.SelectedRoomFilterRoomType)
                    RoomFilterBData.FilterRoomTypeVal.Add(Convert.ToInt32(type));
            }
            // filter Room Title
            if (model.SelectedRoomFilterRoomTitle != null && !(model.RoomIsRemoveRoomTitleFilter))
            {
                RoomFilterBData.FilterRoomTitleVal = new List<string>();
                foreach (var title in model.SelectedRoomFilterRoomTitle)
                    RoomFilterBData.FilterRoomTitleVal.Add(title);
            }
            // Group Name
            RoomFilterBData.GroupName = model.RoomGroupNameTxt;
            // Group Code
            RoomFilterBData.GroupCode = model.RoomGroupCodeTxt;
            // Customer
            RoomFilterBData.Customer = model.RoomCustomerTxt;
            return RoomFilterBData;
        }
        private OperationAttractionsFilterBData OperationAttractionsGridFilterBDatainit(OperationAttractionsGridViewModel model)
        {
            var AttractionsFilterBData = new OperationAttractionsFilterBData();
            // filter Attractions Group Code
            if (model.SelectedAttractionsFilterGroupCode != null && !(model.IsRemoveAttractionsGroupCodeFilter))
            {
                AttractionsFilterBData.FilterAttractionsGroupCodeVal = new List<int?>();
                foreach (var GroupCode in model.SelectedAttractionsFilterGroupCode)
                    AttractionsFilterBData.FilterAttractionsGroupCodeVal.Add(Convert.ToInt32(GroupCode));
            }
            // filter Attractions Group Name
            if (model.SelectedAttractionsFilterGroupName != null && !(model.IsRemoveAttractionsGroupNameFilter))
            {
                AttractionsFilterBData.FilterAttractionsGroupNameVal = new List<int?>();
                foreach (var GroupName in model.SelectedAttractionsFilterGroupName)
                    AttractionsFilterBData.FilterAttractionsGroupNameVal.Add(Convert.ToInt32(GroupName));
            }
            // filter Attractions Customer
            if (model.SelectedAttractionsFilterCustomerCode != null && !(model.IsRemoveAttractionsCustomerCodeFilter))
            {
                AttractionsFilterBData.FilterAttractionsCustomerCodeVal = new List<int?>();
                foreach (var CustomerCode in model.SelectedAttractionsFilterCustomerCode)
                    AttractionsFilterBData.FilterAttractionsCustomerCodeVal.Add(Convert.ToInt32(CustomerCode));
            }
            // filter Attractions Status
            if (model.SelectedAttractionsFilterStatus != null && !(model.IsRemoveAttractionsStatusFilter))
            {
                AttractionsFilterBData.FilterAttractionsStatusVal = new List<int?>();
                foreach (var Status in model.SelectedAttractionsFilterStatus)
                    AttractionsFilterBData.FilterAttractionsStatusVal.Add(Convert.ToInt32(Status));
            }
            // filter Vendor Name
            if (model.SelectedAttractionsFilterVendorName != null && !(model.IsRemoveAttractionsVendorNameFilter))
            {
                AttractionsFilterBData.FilterAttractionsVendorNameVal = new List<int?>();
                foreach (var VendorName in model.SelectedAttractionsFilterVendorName)
                    AttractionsFilterBData.FilterAttractionsVendorNameVal.Add(Convert.ToInt32(VendorName));
            }
            // filter Vendor Type
            if (model.SelectedAttractionsFilterVendorType != null && !(model.IsRemoveAttractionsVendorTypeFilter))
            {
                AttractionsFilterBData.FilterAttractionsVendorTypeVal = new List<int?>();
                foreach (var VendorType in model.SelectedAttractionsFilterVendorType)
                    AttractionsFilterBData.FilterAttractionsVendorTypeVal.Add(Convert.ToInt32(VendorType));
            }
            // filter Vendor City
            if (model.SelectedAttractionsFilterVendorCity != null && !(model.IsRemoveAttractionsVendorCityFilter))
            {
                AttractionsFilterBData.FilterAttractionsVendorCityVal = new List<string>();
                foreach (var vndCity in model.SelectedAttractionsFilterVendorCity)
                    AttractionsFilterBData.FilterAttractionsVendorCityVal.Add(vndCity);
            }
            // filter Restaurant Type 
            if (model.SelectedAttractionsFilterRestaurantType != null && !(model.IsRemoveAttractionsRestaurantTypeFilter))
            {
                AttractionsFilterBData.FilterAttractionsRestaurantTypeVal = new List<string>();
                foreach (var resttype in model.SelectedAttractionsFilterRestaurantType)
                    AttractionsFilterBData.FilterAttractionsRestaurantTypeVal.Add(resttype);
            }
            return AttractionsFilterBData;
        }
        private OperationAttractionsGridBData InitOperationSearchAttractionsBData(OperationAttractionsGridViewModel model)
        {
            OperationAttractionsGridBData Data = new OperationAttractionsGridBData()
            {
                SearchStartToDate = model.AttractionsSearchStartToDate != null && model.AttractionsSearchStartToDate.Length > 0 ? Convert.ToDateTime(model.AttractionsSearchStartToDate) : (DateTime?)null,
                SearchStartFromDate = model.AttractionsSearchStartFromDate != null && model.AttractionsSearchStartFromDate.Length > 0 ? Convert.ToDateTime(model.AttractionsSearchStartFromDate) : (DateTime?)null,
                SearchCustomer = model.AttractionsSearchCustomer,
                SearchGroupCode = model.AttractionsSearchGroupCode,
                SearchGroupName = model.AttractionsSearchGroupName,
                SearchVendorName = model.AttractionsSearchVendorName,
                SearchEmployeeID = model.AttractionsSearchEmployeeID,
            };
            return Data;
        }
        private OperationMiscFilterBData OperationMiscGridFilterBDatainit(OperationMiscGridViewModel model)
        {
            var MiscFilterBData = new OperationMiscFilterBData();
            // filter Misc Group Code
            if (model.SelectedMiscFilterGroupCode != null && !(model.IsRemoveMiscGroupCodeFilter))
            {
                MiscFilterBData.FilterMiscGroupCodeVal = new List<int?>();
                foreach (var GroupCode in model.SelectedMiscFilterGroupCode)
                    MiscFilterBData.FilterMiscGroupCodeVal.Add(Convert.ToInt32(GroupCode));
            }
            // filter Misc Group Name
            if (model.SelectedMiscFilterGroupName != null && !(model.IsRemoveMiscGroupNameFilter))
            {
                MiscFilterBData.FilterMiscGroupNameVal = new List<int?>();
                foreach (var GroupName in model.SelectedMiscFilterGroupName)
                    MiscFilterBData.FilterMiscGroupNameVal.Add(Convert.ToInt32(GroupName));
            }
            // filter Misc Customer
            if (model.SelectedMiscFilterCustomerCode != null && !(model.IsRemoveMiscCustomerCodeFilter))
            {
                MiscFilterBData.FilterMiscCustomerCodeVal = new List<int?>();
                foreach (var CustomerCode in model.SelectedMiscFilterCustomerCode)
                    MiscFilterBData.FilterMiscCustomerCodeVal.Add(Convert.ToInt32(CustomerCode));
            }
            // filter Misc Status
            if (model.SelectedMiscFilterStatus != null && !(model.IsRemoveMiscStatusFilter))
            {
                MiscFilterBData.FilterMiscStatusVal = new List<int?>();
                foreach (var Status in model.SelectedMiscFilterStatus)
                    MiscFilterBData.FilterMiscStatusVal.Add(Convert.ToInt32(Status));
            }
            // filter Vendor Name
            if (model.SelectedMiscFilterVendorName != null && !(model.IsRemoveMiscVendorNameFilter))
            {
                MiscFilterBData.FilterMiscVendorNameVal = new List<int?>();
                foreach (var VendorName in model.SelectedMiscFilterVendorName)
                    MiscFilterBData.FilterMiscVendorNameVal.Add(Convert.ToInt32(VendorName));
            }
            // filter Vendor City
            if (model.SelectedMiscFilterVendorCity != null && !(model.IsRemoveMiscVendorCityFilter))
            {
                MiscFilterBData.FilterMiscVendorCityVal = new List<string>();
                foreach (var vndCity in model.SelectedMiscFilterVendorCity)
                    MiscFilterBData.FilterMiscVendorCityVal.Add(vndCity);
            }
            return MiscFilterBData;
        }
        private OperationMiscGridBData InitOperationSearchMiscBData(OperationMiscGridViewModel model)
        {
            OperationMiscGridBData Data = new OperationMiscGridBData()
            {
                SearchStartToDate = model.MiscSearchStartToDate != null && model.MiscSearchStartToDate.Length > 0 ? Convert.ToDateTime(model.MiscSearchStartToDate) : (DateTime?)null,
                SearchStartFromDate = model.MiscSearchStartFromDate != null && model.MiscSearchStartFromDate.Length > 0 ? Convert.ToDateTime(model.MiscSearchStartFromDate) : (DateTime?)null,
                SearchCustomer = model.MiscSearchCustomer,
                SearchGroupCode = model.MiscSearchGroupCode,
                SearchGroupName = model.MiscSearchGroupName,
                SearchVendorName = model.MiscSearchVendorName,
                SearchEmployeeID = model.MiscSearchEmployeeID,
            };
            return Data;
        }
        private OperationBusFilterBData OperationBusGridFilterBDatainit(OperationBusGridViewModel model)
        {
            var BusFilterBData = new OperationBusFilterBData();
            // filter Bus Group Code
            if (model.SelectedBusFilterGroupCode != null && !(model.IsRemoveBusGroupCodeFilter))
            {
                BusFilterBData.FilterBusGroupCodeVal = new List<int?>();
                foreach (var GroupCode in model.SelectedBusFilterGroupCode)
                    BusFilterBData.FilterBusGroupCodeVal.Add(Convert.ToInt32(GroupCode));
            }
            // filter Bus Group Name
            if (model.SelectedBusFilterGroupName != null && !(model.IsRemoveBusGroupNameFilter))
            {
                BusFilterBData.FilterBusGroupNameVal = new List<int?>();
                foreach (var GroupName in model.SelectedBusFilterGroupName)
                    BusFilterBData.FilterBusGroupNameVal.Add(Convert.ToInt32(GroupName));
            }
            // filter Bus Customer
            if (model.SelectedBusFilterCustomerCode != null && !(model.IsRemoveBusCustomerCodeFilter))
            {
                BusFilterBData.FilterBusCustomerCodeVal = new List<int?>();
                foreach (var CustomerCode in model.SelectedBusFilterCustomerCode)
                    BusFilterBData.FilterBusCustomerCodeVal.Add(Convert.ToInt32(CustomerCode));
            }
            // filter Attractions Status
            if (model.SelectedBusFilterStatus != null && !(model.IsRemoveBusStatusFilter))
            {
                BusFilterBData.FilterBusStatusVal = new List<int?>();
                foreach (var Status in model.SelectedBusFilterStatus)
                    BusFilterBData.FilterBusStatusVal.Add(Convert.ToInt32(Status));
            }
            // filter Vendor Name
            if (model.SelectedBusFilterVendorName != null && !(model.IsRemoveBusVendorNameFilter))
            {
                BusFilterBData.FilterBusVendorNameVal = new List<int?>();
                foreach (var VendorName in model.SelectedBusFilterVendorName)
                    BusFilterBData.FilterBusVendorNameVal.Add(Convert.ToInt32(VendorName));
            }
            // filter Start City
            if (model.SelectedBusFilterStartCity != null && !(model.IsRemoveBusStartCityFilter))
            {
                BusFilterBData.FilterBusStartCityVal = new List<string>();
                foreach (var StartCity in model.SelectedBusFilterStartCity)
                    BusFilterBData.FilterBusStartCityVal.Add(StartCity);
            }
            // filter End City
            if (model.SelectedBusFilterEndCity != null && !(model.IsRemoveBusEndCityFilter))
            {
                BusFilterBData.FilterBusEndCityVal = new List<string>();
                foreach (var EndCity in model.SelectedBusFilterEndCity)
                    BusFilterBData.FilterBusEndCityVal.Add(EndCity);
            }
            return BusFilterBData;
        }
        private OperationBusGridBData InitOperationSearchBusBData(OperationBusGridViewModel model)
        {
            OperationBusGridBData Data = new OperationBusGridBData()
            {
                SearchStartToDate = model.BusSearchStartToDate != null && model.BusSearchStartToDate.Length > 0 ? Convert.ToDateTime(model.BusSearchStartToDate) : (DateTime?)null,
                SearchStartFromDate = model.BusSearchStartFromDate != null && model.BusSearchStartFromDate.Length > 0 ? Convert.ToDateTime(model.BusSearchStartFromDate) : (DateTime?)null,
                SearchCustomer = model.BusSearchCustomer,
                SearchGuideName = model.BusSearchGuideName,
                SearchGroupCode = model.BusSearchGroupCode,
                SearchGroupName = model.BusSearchGroupName,
                SearchVendorName = model.BusSearchVendorName,
                SearchEmployeeID = model.BusSearchEmployeeID,
                SearchStartCity = model.BusSearchStartCity,
                SearchEndCity = model.BusSearchEndCity,
            };
            return Data;
        }
        private OperationGroupCheckListFilterBData OperationGroupCheckListGridFilterBDatainit(OperationGroupCheckListGridViewModel model)
        {
            var GroupCheckListFilterBData = new OperationGroupCheckListFilterBData();
            // filter Bus Group Code
            if (model.SelectedGroupCheckListFilterGroupCode != null && !(model.IsRemoveGroupCheckListGroupCodeFilter))
            {
                GroupCheckListFilterBData.FilterGroupCheckListGroupCodeVal = new List<int?>();
                foreach (var GroupCode in model.SelectedGroupCheckListFilterGroupCode)
                    GroupCheckListFilterBData.FilterGroupCheckListGroupCodeVal.Add(Convert.ToInt32(GroupCode));
            }
            // filter Bus Group Name
            if (model.SelectedGroupCheckListFilterGroupName != null && !(model.IsRemoveGroupCheckListGroupNameFilter))
            {
                GroupCheckListFilterBData.FilterGroupCheckListGroupNameVal = new List<int?>();
                foreach (var GroupName in model.SelectedGroupCheckListFilterGroupName)
                    GroupCheckListFilterBData.FilterGroupCheckListGroupNameVal.Add(Convert.ToInt32(GroupName));
            }
            // filter Bus Customer
            if (model.SelectedGroupCheckListFilterCustomerCode != null && !(model.IsRemoveGroupCheckListCustomerCodeFilter))
            {
                GroupCheckListFilterBData.FilterGroupCheckListCustomerCodeVal = new List<int?>();
                foreach (var CustomerCode in model.SelectedGroupCheckListFilterCustomerCode)
                    GroupCheckListFilterBData.FilterGroupCheckListCustomerCodeVal.Add(Convert.ToInt32(CustomerCode));
            }
           
            return GroupCheckListFilterBData;
        }
        private OperationGroupCheckListGridBData InitOperationSearchGroupCheckListBData(OperationGroupCheckListGridViewModel model)
        {
            OperationGroupCheckListGridBData Data = new OperationGroupCheckListGridBData()
            {
                SearchCustomer = model.GroupCheckListSearchCustomer,
                SearchGroupCode = model.GroupCheckListSearchGroupCode,
                SearchGroupName = model.GroupCheckListSearchGroupName,
                SearchSelectedIsGir = model.GroupCheckListSearchSelectedIsGir,
            };
            return Data;
        }
        private OperationHotelGridBData OperationHotelGridSaveBDatainit(OperationHotelGridViewModel model)
        {
            var HotelGridBData = new OperationHotelGridBData();
            HotelGridBData.SaveRows = new List<OperationHotelGridSaveRowBData>();
            // init Search
            HotelGridBData.SearchCheckInFromDate = model.SearchCheckInFromDate != null ? Convert.ToDateTime(model.SearchCheckInFromDate) : (DateTime?)null;
            HotelGridBData.SearchCheckInToDate = model.SearchCheckInToDate != null ? Convert.ToDateTime(model.SearchCheckInToDate) : (DateTime?)null;
            HotelGridBData.SearchCheckOutFromDate = model.SearchCheckOutFromDate != null ? Convert.ToDateTime(model.SearchCheckOutFromDate) : (DateTime?)null;
            HotelGridBData.SearchCheckOutToDate = model.SearchCheckOutFromDate != null ? Convert.ToDateTime(model.SearchCheckOutToDate) : (DateTime?)null;
            HotelGridBData.SearchCustomer = model.SearchCustomer;
            HotelGridBData.SearchFlightNo = model.SearchFlightNo;
            HotelGridBData.SearchEmployeeID = model.SearchEmployeeID;
            HotelGridBData.SearchGroupCode = model.SearchGroupCode;
            HotelGridBData.SearchGroupName = model.SearchGroupName;
            HotelGridBData.SearchVendorName = model.SearchVendorName;
            HotelGridBData.SelectedSearchArrivalCity = model.SelectedSearchArrivalCity;
            HotelGridBData.SelectedSearchDepartureCity = model.SelectedSearchDepartureCity;
            HotelGridBData.SelectedSearchNationality = model.SelectedSearchNationality != null ? Convert.ToInt32(model.SelectedSearchNationality) : (int?)null;
            HotelGridBData.SelectedSearchStatus = model.SelectedSearchStatus != null ? Convert.ToInt32(model.SelectedSearchStatus) : (int?)null;
            if (model != null && model.SaveRows != null)
                foreach (var row in model.SaveRows)
                {
                    HotelGridBData.SaveRows.Add(new OperationHotelGridSaveRowBData
                    {
                        GroupID = row.GroupID,
                        VendorID = row.VendorID,
                        NewVendorID = row.NewVendorID != null ? Convert.ToInt32(row.NewVendorID) : (int?)null,
                        ArrivalDate = row.ArrivalDate != null ? Convert.ToDateTime(row.ArrivalDate): (DateTime?)null,
                        DepartureDate = row.DepartureDate != null ? Convert.ToDateTime(row.DepartureDate): (DateTime?)null,
                        SelectedGroupStatus = row.SelectedGroupStatus,
                        SelectedVendorStatus = row.SelectedVendorStatus,
                        ArrivalCity = row.ArrivalCity,
                        AccountingMemo = row.AccountingMemo,
                        ClientBookingCode = row.ClientBookingCode,
                        EmployeeID = row.SelectedEmployeeID,
                        ExtraCost = row.ExtraCost,
                        RefundReceivedHotel = row.RefundReceivedHotel,
                        TotalInvoice = row.TotalInvoice,
                        TotalCharged = row.TotalCharged,
                        FirstPayment = row.FirstPayment != null ? Convert.ToDecimal(row.FirstPayment) : (decimal?)null,
                        FirstPaymentDate = row.DateFirstPayment != null ? Convert.ToDateTime(row.DateFirstPayment) : (DateTime?)null,
                        FirstPaymentMethod = row.SelectedFirstPaymentMethod, 
                        SecondPayment = row.SecondPayment != null ? Convert.ToDecimal(row.SecondPayment) : (decimal?)null,
                        SecondPaymentDate = row.DateSecondPayment != null ? Convert.ToDateTime(row.DateSecondPayment) : (DateTime?)null,
                        SecondPaymentMethod = row.SelectedSecondPaymentMethod, 
                        ThirdPayment = row.ThirdPayment != null ? Convert.ToDecimal(row.ThirdPayment) : (decimal?)null,
                        ThirdPaymentDate = row.DateThirdPayment != null ? Convert.ToDateTime(row.DateThirdPayment) : (DateTime?)null,
                        ThirdPaymentMethod = row.SelectedThirdPaymentMethod,
                        CommissionPerc = row.CommissionPerc != null ? Convert.ToDouble(row.CommissionPerc) : (double?)null,
                        CommissionStatus = row.CommissionStatus,
                        CommissionRecAmt = row.CommissionRecAmt != null ? Convert.ToDecimal(row.CommissionRecAmt) : (decimal?)null,
                        CommissionRecDate = row.CommissionRecDate != null ? Convert.ToDateTime(row.CommissionRecDate) : (DateTime?)null,
                        CommissionCheckNum = row.CommissionCheckNum,
                        CommissionCheckAmt = row.CommissionCheckAmt != null ? Convert.ToDecimal(row.CommissionCheckAmt) : (decimal?)null,
                        Luggage = row.Luggage != null ? Convert.ToDecimal(row.Luggage) : (decimal?)null,
                        ABF = row.ABF != null ? Convert.ToDecimal(row.ABF) : (decimal?)null,
                        CBF = row.CBF != null ? Convert.ToDecimal(row.CBF) : (decimal?)null,
                        Lunch = row.Lunch != null ? Convert.ToDecimal(row.Lunch) : (decimal?)null,
                        Dinner = row.Dinner != null ? Convert.ToDecimal(row.Dinner) : (decimal?)null,
                        LuggageChecked = row.LuggageChecked,
                        ABFChecked = row.ABFChecked,
                        CBFChecked = row.CBFChecked,
                        LunchChecked = row.LunchChecked,
                        DinnerChecked = row.DinnerChecked,
                        Tax = row.Tax != null ? Convert.ToDecimal(row.Tax) : (decimal?)null,
                        OccTax = row.OccTax != null ? Convert.ToDecimal(row.OccTax) : (decimal?)null,
                        SingleAmount = row.SingleAmt != null ? Convert.ToDecimal(row.SingleAmt) : (decimal?)null,
                        DoubleAmount = row.DoubleAmt != null ? Convert.ToDecimal(row.DoubleAmt) : (decimal?)null,
                        TwinAmount = row.TwinAmt != null ? Convert.ToDecimal(row.TwinAmt) : (decimal?)null,
                        TripleAmount = row.TrpAmt != null ? Convert.ToDecimal(row.TrpAmt) : (decimal?)null,
                        QuadAmount = row.QuadAmt != null ? Convert.ToDecimal(row.QuadAmt) : (decimal?)null,
                        GuideAmount = row.GuideAmt != null ? Convert.ToDecimal(row.GuideAmt) : (decimal?)null,
                        DriverAmount = row.DriverAmt != null ? Convert.ToDecimal(row.DriverAmt) : (decimal?)null,
                        Comp = row.Comp != null ? Convert.ToInt16(row.Comp) : (short)0,
                        Notes = row.Notes,
                        BookedUnder = row.BookedUnder,
                    });
                }
            return HotelGridBData;
        }
        private OperationRoomGridBData OperationRoomGridSaveBDatainit(OperationRoomGridViewModel model)
        {
            var RoomGridBData = new OperationRoomGridBData();
            RoomGridBData.Rows = new List<OperationRoomGridRowBData>();
            RoomGridBData.GroupID = model.RoomGroupIDTxt;
            if (model != null && model.Rows != null)
                foreach(var row in model.Rows)
                {
                    RoomGridBData.Rows.Add(new OperationRoomGridRowBData
                    {
                        GroupID = row.RoomGroupID,
                        LineNo = row.RoomLineNo,
                        ServiceID = Convert.ToInt32(row.RoomSelectedRoomType),
                        Title = row.RoomSelectedRoomTitle,
                        Names = row.RoomNames,
                        Notes = row.RoomNotes,
                        CustomerID = row.RoomCustomerId,
                        NumOfPerson = Convert.ToInt16(row.RoomNoOfPerson),
                        NumOfPersonRoom = Convert.ToInt16(row.RoomNumOfPersonRoom),
                        FullBoard = row.RoomFullBoard == "Yes" ? true : false,
                        FullBoardCount = row.RoomFullBoardCount != null ? Convert.ToInt16(row.RoomFullBoardCount) : (short?)null,
                    });
                }
            return RoomGridBData;
        }
        private OperationAttractionsGridBData OperationAttractionsGridSaveBDatainit(OperationAttractionsGridViewModel model)
        {
            var AttractionsGridBData = new OperationAttractionsGridBData();
            AttractionsGridBData.SaveRows = new List<OperationAttractionsGridSaveRowBData>();
            // init Search
            AttractionsGridBData.SearchStartFromDate = model.AttractionsSearchStartFromDate != null ? Convert.ToDateTime(model.AttractionsSearchStartFromDate) : (DateTime?)null;
            AttractionsGridBData.SearchStartToDate = model.AttractionsSearchStartToDate != null ? Convert.ToDateTime(model.AttractionsSearchStartToDate) : (DateTime?)null;
            AttractionsGridBData.SearchCustomer = model.AttractionsSearchCustomer;
            AttractionsGridBData.SearchGroupCode = model.AttractionsSearchGroupCode;
            AttractionsGridBData.SearchGroupName = model.AttractionsSearchGroupName;
            AttractionsGridBData.SearchVendorName = model.AttractionsSearchVendorName;
            AttractionsGridBData.SearchEmployeeID = model.AttractionsSearchEmployeeID;
            if (model != null && model.SaveRows != null)
                foreach (var row in model.SaveRows)
                {
                    AttractionsGridBData.SaveRows.Add(new OperationAttractionsGridSaveRowBData
                    {
                        GroupID = row.GroupID,
                        VendorID = row.VendorID,
                        NewVendorID = row.NewVendorID != null ? Convert.ToInt32(row.NewVendorID) : (int?)null,
                        Pax = row.Pax != null ? Convert.ToInt16(row.Pax) : (short?)null,
                        StartDate = row.StartDate != null ? Convert.ToDateTime(row.StartDate) : (DateTime?)null,
                        NewStartDate = row.NewStartDate != null ? Convert.ToDateTime(row.NewStartDate) : (DateTime?)null,
                        Done = row.Done != null ? Convert.ToDateTime(row.Done) : (DateTime?)null,
                        DepositDate = row.DepositDate != null ? Convert.ToDateTime(row.DepositDate) : (DateTime?)null,
                        Time = row.Time != null ? Convert.ToDateTime(row.Time) : (DateTime?)null,
                        FinalPayment = row.FinalPayment != null ? Convert.ToDecimal(row.FinalPayment) : (decimal?)null,
                        EmployeeID = row.SelectedEmployeeID,
                        CCMemo = row.CCMemo,
                        QuotaCurr = row.QuotaCurr,
                        RestCategory = row.Type,
                        OldRestCategory = row.OldRestCategory,
                        SelectedVendorStatus = row.AttractionsSelectedVendorStatus,
                        SelectedVendorRestService = row.AttractionsSelectedRestService,
                        DepositAmtPaid = row.DepositAmtPaid != null ? Convert.ToDecimal(row.DepositAmtPaid) : (decimal?)null,
                        GuideInvoicePrice = row.GuideInvoicePrice != null ? Convert.ToDecimal(row.GuideInvoicePrice) : (decimal?)null,
                        IsGuideInvoice = row.IsGuideInvoice,
                        InvoicePrice = row.InvoicePrice != null ? Convert.ToDecimal(row.InvoicePrice) : (decimal?)null,
                        IsInvoice = row.IsInvoice,
                        CCChargeAmt = row.CCChargeAmt != null ? Convert.ToDecimal(row.CCChargeAmt) : (decimal?)null,
                        Deposit = row.Deposit != null ? Convert.ToDecimal(row.Deposit) : (decimal?)null,
                        UnitRate = row.UnitRate != null ? Convert.ToDecimal(row.UnitRate) : (decimal?)null,
                        FirstPayAmt = row.AttractionsFirstPayment != null ? Convert.ToDecimal(row.AttractionsFirstPayment) : (decimal?)null,
                        FirstPayDate = row.AttractionsDateFirstPayment != null ? Convert.ToDateTime(row.AttractionsDateFirstPayment) : (DateTime?)null,
                        FirstPayMethod = row.AttractionsSelectedFirstPaymentMethod,
                        SecondPayAmt = row.AttractionsSecondPayment != null ? Convert.ToDecimal(row.AttractionsSecondPayment) : (decimal?)null,
                        SecondPayDate = row.AttractionsDateSecondPayment != null ? Convert.ToDateTime(row.AttractionsDateSecondPayment) : (DateTime?)null,
                        SecondPayMethod = row.AttractionsSelectedSecondPaymentMethod,
                        ThirdPayAmt = row.AttractionsThirdPayment != null ? Convert.ToDecimal(row.AttractionsThirdPayment) : (decimal?)null,
                        ThirdPayDate = row.AttractionsDateThirdPayment != null ? Convert.ToDateTime(row.AttractionsDateThirdPayment) : (DateTime?)null,
                        ThirdPayMethod = row.AttractionsSelectedThirdPaymentMethod,
                    });
                }
            return AttractionsGridBData;
        }
        private OperationMiscGridBData OperationMiscGridSaveBDatainit(OperationMiscGridViewModel model)
        {
            var MiscGridBData = new OperationMiscGridBData();
            MiscGridBData.SaveRows = new List<OperationMiscGridSaveRowBData>();
            // init Search
            MiscGridBData.SearchStartFromDate = model.MiscSearchStartFromDate != null ? Convert.ToDateTime(model.MiscSearchStartFromDate) : (DateTime?)null;
            MiscGridBData.SearchStartToDate = model.MiscSearchStartToDate != null ? Convert.ToDateTime(model.MiscSearchStartToDate) : (DateTime?)null;
            MiscGridBData.SearchCustomer = model.MiscSearchCustomer;
            MiscGridBData.SearchGroupCode = model.MiscSearchGroupCode;
            MiscGridBData.SearchGroupName = model.MiscSearchGroupName;
            MiscGridBData.SearchVendorName = model.MiscSearchVendorName;
            MiscGridBData.SearchEmployeeID = model.MiscSearchEmployeeID;
            if (model != null && model.SaveRows != null)
                foreach (var row in model.SaveRows)
                {
                    MiscGridBData.SaveRows.Add(new OperationMiscGridSaveRowBData
                    {
                        GroupID = row.GroupID,
                        VendorID = row.VendorID,
                        NewVendorID = row.NewVendorID != null ? Convert.ToInt32(row.NewVendorID) : (int?)null,
                        StartDate = row.StartDate != null ? Convert.ToDateTime(row.StartDate) : (DateTime?)null,
                        NewStartDate = row.NewStartDate != null ? Convert.ToDateTime(row.NewStartDate) : (DateTime?)null,
                        Time = row.Time != null ? Convert.ToDateTime(row.Time) : (DateTime?)null,
                        EmployeeID = row.SelectedEmployeeID,
                        Notes = row.Notes,
                        ServiceID = row.SelectedDetailID,
                        QuotaCurr = row.QuotaCurr,
                        SelectedVendorStatus = row.MiscSelectedVendorStatus,
                        Pax = row.Pax != null ? Convert.ToInt16(row.Pax) : (short?)null,
                        Plane = row.Plane,
                        IsComp = row.IsComp,
                        UnitPrice = row.UnitPrice != null ? Convert.ToDecimal(row.UnitPrice) : (decimal?)null,
                        UnitPricePG = row.UnitPricePG != null ? Convert.ToDecimal(row.UnitPricePG) : (decimal?)null,
                        FirstPayAmt = row.FirstPayment != null ? Convert.ToDecimal(row.FirstPayment) : (decimal?)null,
                        FirstPayDate = row.DateFirstPayment != null ? Convert.ToDateTime(row.DateFirstPayment) : (DateTime?)null,
                        FirstPayMethod = row.SelectedFirstPaymentMethod,
                        SecondPayAmt = row.SecondPayment != null ? Convert.ToDecimal(row.SecondPayment) : (decimal?)null,
                        SecondPayDate = row.DateSecondPayment != null ? Convert.ToDateTime(row.DateSecondPayment) : (DateTime?)null,
                        SecondPayMethod = row.SelectedSecondPaymentMethod,
                        ThirdPayAmt = row.ThirdPayment != null ? Convert.ToDecimal(row.ThirdPayment) : (decimal?)null,
                        ThirdPayDate = row.DateThirdPayment != null ? Convert.ToDateTime(row.DateThirdPayment) : (DateTime?)null,
                        ThirdPayMethod = row.SelectedThirdPaymentMethod,
                    });
                }
            return MiscGridBData;
        }
        private OperationBusGridBData OperationBusGridSaveBDatainit(OperationBusGridViewModel model)
        {
            var BusGridBData = new OperationBusGridBData();
            BusGridBData.SaveRows = new List<OperationBusGridSaveRowBData>();
            // init Search
            BusGridBData.SearchStartFromDate = model.BusSearchStartFromDate != null ? Convert.ToDateTime(model.BusSearchStartFromDate) : (DateTime?)null;
            BusGridBData.SearchStartToDate = model.BusSearchStartToDate != null ? Convert.ToDateTime(model.BusSearchStartToDate) : (DateTime?)null;
            BusGridBData.SearchCustomer = model.BusSearchCustomer;
            BusGridBData.SearchGuideName = model.BusSearchGuideName;
            BusGridBData.SearchGroupCode = model.BusSearchGroupCode;
            BusGridBData.SearchGroupName = model.BusSearchGroupName;
            BusGridBData.SearchVendorName = model.BusSearchVendorName;
            BusGridBData.SearchStartCity = model.BusSearchStartCity;
            BusGridBData.SearchEndCity = model.BusSearchEndCity;
            BusGridBData.SearchEmployeeID = model.BusSearchEmployeeID;
            if (model != null && model.SaveRows != null)
                foreach (var row in model.SaveRows)
                {
                    BusGridBData.SaveRows.Add(new OperationBusGridSaveRowBData
                    {
                        GroupID = row.GroupID,
                        VendorID = row.VendorID,
                        SelectedGuideID = row.GuideID,
                        NewVendorID = row.NewVendorID != null ? Convert.ToInt32(row.NewVendorID) : (int?)null,
                        NewSelectedGuideID = row.NewGuideID != null ? Convert.ToInt32(row.NewGuideID) : (int?)null,
                        Pax = row.Pax != null ? Convert.ToInt16(row.Pax) : (short?)null,
                        SelectedVendorStatus = row.BusSelectedVendorStatus,
                        ServiceID = row.SelectedServiceID,
                        ServiceDetailID = row.SelectedDetailID,
                        EmployeeID = row.SelectedEmployeeID,
                        StartDate = row.StartDate != null ? Convert.ToDateTime(row.StartDate) : (DateTime?)null,
                        NewStartDate = row.NewStartDate != null ? Convert.ToDateTime(row.NewStartDate) : (DateTime?)null,
                        Time = row.Time != null ? Convert.ToDateTime(row.Time) : (DateTime?)null,
                        NewTime = row.NewTime != null ? Convert.ToDateTime(row.NewTime) : (DateTime?)null,
                        ServiceDate = row.DateOfService != null ? Convert.ToDateTime(row.DateOfService) : (DateTime?)null,
                        StartCity = row.StartCity,
                        EndCity = row.EndCity,
                        BusCount = row.BusCount != null ? Convert.ToInt32(row.BusCount) : (int?)null,
                        BusSize = row.BusSize != null ? Convert.ToInt32(row.BusSize) : (int?)null,
                        BusPrice = row.BusPrice != null ? Convert.ToDecimal(row.BusPrice) : (decimal?)null,
                        GuideAddCharge = row.GuideAddCharge != null ? Convert.ToDecimal(row.GuideAddCharge) : (decimal?)null,
                        GuidePaidAmt = row.GuidePaidAmt != null ? Convert.ToDecimal(row.GuidePaidAmt) : (decimal?)null,
                        GuideSalary = row.GuideSalary != null ? Convert.ToDecimal(row.GuideSalary) : (decimal?)null,
                        GuideMisc = row.GuideMisc != null ? Convert.ToDecimal(row.GuideMisc) : (decimal?)null,
                        GuideStepOn = row.GuideStepOn != null ? Convert.ToDecimal(row.GuideStepOn) : (decimal?)null,
                        GuideSalaryPaid = row.GuideSalaryPaid != null ? Convert.ToDecimal(row.GuideSalaryPaid) : (decimal?)null,
                        Airport = row.Airport,
                        Notes = row.BusNotes,
                        QuotaCurr = row.BusQuotaCurr,
                        InvoicePrice = row.InvoicePrice != null ? Convert.ToDecimal(row.InvoicePrice) : (decimal?)null,
                        IsInvoice = row.IsInvoice,
                        FirstPayAmt = row.BusFirstPayment != null ? Convert.ToDecimal(row.BusFirstPayment) : (decimal?)null,
                        FirstPayDate = row.BusDateFirstPayment != null ? Convert.ToDateTime(row.BusDateFirstPayment) : (DateTime?)null,
                        FirstPayMethod = row.BusSelectedFirstPaymentMethod,
                        SecondPayAmt = row.BusSecondPayment != null ? Convert.ToDecimal(row.BusSecondPayment) : (decimal?)null,
                        SecondPayDate = row.BusDateSecondPayment != null ? Convert.ToDateTime(row.BusDateSecondPayment) : (DateTime?)null,
                        SecondPayMethod = row.BusSelectedSecondPaymentMethod,
                        ThirdPayAmt = row.BusThirdPayment != null ? Convert.ToDecimal(row.BusThirdPayment) : (decimal?)null,
                        ThirdPayDate = row.BusDateThirdPayment != null ? Convert.ToDateTime(row.BusDateThirdPayment) : (DateTime?)null,
                        ThirdPayMethod = row.BusSelectedThirdPaymentMethod,
                        GuideFirstPayAmt = row.BusGuideFirstPayment != null ? Convert.ToDecimal(row.BusGuideFirstPayment) : (decimal?)null,
                        GuideFirstPayDate = row.BusGuideDateFirstPayment != null ? Convert.ToDateTime(row.BusGuideDateFirstPayment) : (DateTime?)null,
                        GuideFirstPayMethod = row.BusGuideSelectedFirstPaymentMethod,
                        GuideSecondPayAmt = row.BusGuideSecondPayment != null ? Convert.ToDecimal(row.BusGuideSecondPayment) : (decimal?)null,
                        GuideSecondPayDate = row.BusGuideDateSecondPayment != null ? Convert.ToDateTime(row.BusGuideDateSecondPayment) : (DateTime?)null,
                        GuideSecondPayMethod = row.BusGuideSelectedSecondPaymentMethod,
                        GuideThirdPayAmt = row.BusGuideThirdPayment != null ? Convert.ToDecimal(row.BusGuideThirdPayment) : (decimal?)null,
                        GuideThirdPayDate = row.BusGuideDateThirdPayment != null ? Convert.ToDateTime(row.BusGuideDateThirdPayment) : (DateTime?)null,
                        GuideThirdPayMethod = row.BusGuideSelectedThirdPaymentMethod,
                    });
                }
            return BusGridBData;
        }
        private OperationTechProgGridBData OperationTechProgGridSaveBDatainit(OperationTechProgGridViewModel model)
        {
            var TechProgGridBData = new OperationTechProgGridBData();
            TechProgGridBData.GroupCode = model.TechProgSearchGroupCode;
            TechProgGridBData.GroupID = model.TechProgGroupIDTxt;
            TechProgGridBData.SaveRows = new List<OperationTechProgGridSaveRowBData>();
            if (model != null && model.SaveRows != null)
                foreach (var row in model.SaveRows)
                {
                    TechProgGridBData.SaveRows.Add(new OperationTechProgGridSaveRowBData
                    {
                        GroupID = row.TechProgGroupID,
                        DetailID = row.TechProgDetailID,
                        Desc = row.TechProgDesc,
                        Via = row.TechProgVia,
                        PrnFlag = row.TechProgPrnFlag,
                        Date = row.TechProgDate != null ? Convert.ToDateTime(row.TechProgDate) : DateTime.Now,
                        Time = row.TechProgTime != null ? Convert.ToDateTime(row.TechProgTime).TimeOfDay : DateTime.Now.TimeOfDay,
                        OldTime = row.TechProgOldTime != null ? Convert.ToDateTime(row.TechProgOldTime).TimeOfDay : DateTime.Now.TimeOfDay,
                    });
                }
            return TechProgGridBData;
        }
        private void OperationHotelInitModelState(OperationHotelGridViewModel OperHotelGridView, OperationHotelGridViewModel model, double? Count)
        {
            OperHotelGridView.Count = (model.HotelPageNumber == 0 ? "1" : model.HotelPageNumber.ToString()) + " of " + (Count != null ? ((int)Math.Ceiling((double)Count / (double)OperationHotelGridBData.TakeCount)).ToString() : "1");
            OperHotelGridView.CountCheck = Count != null ? ((int)Math.Ceiling((double)Count / (double)OperationHotelGridBData.TakeCount)) : 1;
            // init Scrolls
            OperHotelGridView.LeftScrollPossition = model.LeftScrollPossition;
            OperHotelGridView.TopScrollPossition = model.TopScrollPossition;
            // init search part elements
            OperHotelGridView.SearchCheckInFromDate = model.SearchCheckInFromDate;
            OperHotelGridView.SearchCheckInToDate = model.SearchCheckInToDate;
            OperHotelGridView.SearchCheckOutFromDate = model.SearchCheckOutFromDate;
            OperHotelGridView.SearchCheckOutToDate = model.SearchCheckOutToDate;
            OperHotelGridView.SearchCustomer = model.SearchCustomer;
            OperHotelGridView.SearchFlightNo = model.SearchFlightNo;
            OperHotelGridView.SearchEmployee = model.SearchEmployee;
            OperHotelGridView.SearchEmployeeID = model.SearchEmployeeID;
            OperHotelGridView.SearchGroupCode = model.SearchGroupCode;
            OperHotelGridView.SearchGroupName = model.SearchGroupName;
            OperHotelGridView.SearchVendorName = model.SearchVendorName;
            OperHotelGridView.SelectedSearchArrivalCity = model.SelectedSearchArrivalCity;
            OperHotelGridView.SelectedSearchDepartureCity = model.SelectedSearchDepartureCity;
            OperHotelGridView.SelectedSearchNationality = model.SelectedSearchNationality;
            
            // init all view elements
            OperHotelGridView.ViewGroupStatus = model.ViewGroupStatus;
            OperHotelGridView.ViewVendorStatus = model.ViewVendorStatus;
            OperHotelGridView.ViewGroupCode = model.ViewGroupCode;
            OperHotelGridView.ViewGroupName = model.ViewGroupName;
            OperHotelGridView.ViewCustomerCode = model.ViewCustomerCode;
            OperHotelGridView.ViewPax = model.ViewPax;
            OperHotelGridView.ViewArrivalDate = model.ViewArrivalDate;
            OperHotelGridView.ViewArrivalCity = model.ViewArrivalCity;
            OperHotelGridView.ViewDepartureDate = model.ViewDepartureDate;
            //OperHotelGridView.ViewDepartureCity = model.ViewDepartureCity;
            OperHotelGridView.ViewFileCompDays = model.ViewFileCompDays;
            OperHotelGridView.ViewNights = model.ViewNights;
            OperHotelGridView.ViewRoomCount = model.ViewRoomCount;
            OperHotelGridView.ViewEmployee = model.ViewEmployee;
            OperHotelGridView.ViewTotalCost = model.ViewTotalCost;
            OperHotelGridView.ViewBreakDownTotal = model.ViewBreakDownTotal;
            OperHotelGridView.ViewOutstandingBalance = model.ViewOutstandingBalance;
            OperHotelGridView.ViewComAmount = model.ViewComAmount;
            OperHotelGridView.ViewComDifference = model.ViewComDifference;
            OperHotelGridView.ViewCurrency = model.ViewCurrency;
            OperHotelGridView.ViewTotalInvoice = model.ViewTotalInvoice;
            OperHotelGridView.ViewTotalPaid = model.ViewTotalPaid;
            OperHotelGridView.ViewFirstPayment = model.ViewFirstPayment;
            OperHotelGridView.ViewFirstPaymentMethod = model.ViewFirstPaymentMethod;
            OperHotelGridView.ViewDateFirstPayment = model.ViewDateFirstPayment;
            OperHotelGridView.ViewSecondPayment = model.ViewSecondPayment;
            OperHotelGridView.ViewSecondPaymentMethod = model.ViewSecondPaymentMethod;
            OperHotelGridView.ViewDateSecondPayment = model.ViewDateSecondPayment;
            OperHotelGridView.ViewThirdPayment = model.ViewThirdPayment;
            OperHotelGridView.ViewThirdPaymentMethod = model.ViewThirdPaymentMethod;
            OperHotelGridView.ViewDateThirdPayment = model.ViewDateThirdPayment;
            OperHotelGridView.ViewRefundReceivedHotel = model.ViewRefundReceivedHotel;
            OperHotelGridView.ViewTotalCharged = model.ViewTotalCharged;
            OperHotelGridView.ViewAuthDiff = model.ViewAuthDiff;
            OperHotelGridView.ViewAccountingMemo = model.ViewAccountingMemo;
            OperHotelGridView.ViewCommissionStatus = model.ViewCommissionStatus;
            OperHotelGridView.ViewCommissionPrc = model.ViewCommissionPrc;
            OperHotelGridView.ViewCommissionReceived = model.ViewCommissionReceived;
            OperHotelGridView.ViewCommissionDateReceived = model.ViewCommissionDateReceived;
            OperHotelGridView.ViewCheckNumber = model.ViewCheckNumber;
            OperHotelGridView.ViewCheckAmount = model.ViewCheckAmount;
            OperHotelGridView.ViewSGLCount = model.ViewSGLCount;
            OperHotelGridView.ViewSGLAmount = model.ViewSGLAmount;
            OperHotelGridView.ViewDBLCount = model.ViewDBLCount;
            OperHotelGridView.ViewDBLAmount = model.ViewDBLAmount;
            OperHotelGridView.ViewTWNCount = model.ViewTWNCount;
            OperHotelGridView.ViewTWNAmount = model.ViewTWNAmount;
            OperHotelGridView.ViewTRPLCount = model.ViewTRPLCount;
            OperHotelGridView.ViewTRPLAmount = model.ViewTRPLAmount;
            OperHotelGridView.ViewQUDCount = model.ViewQUDCount;
            OperHotelGridView.ViewQUDAmount = model.ViewQUDAmount;
            OperHotelGridView.ViewGuideCount = model.ViewGuideCount;
            OperHotelGridView.ViewGuideAmount = model.ViewGuideAmount;
            OperHotelGridView.ViewDriverCount = model.ViewDriverCount;
            OperHotelGridView.ViewDriverAmount = model.ViewDriverAmount;
            OperHotelGridView.ViewTaxPrc = model.ViewTaxPrc;
            OperHotelGridView.ViewOccTax = model.ViewOccTax;
            OperHotelGridView.ViewBag = model.ViewBag;
            OperHotelGridView.ViewCBF = model.ViewCBF;
            OperHotelGridView.ViewABF = model.ViewABF;
            OperHotelGridView.ViewLunch = model.ViewLunch;
            OperHotelGridView.ViewDinner = model.ViewDinner;
            OperHotelGridView.ViewVConfHtml = model.ViewVConfHtml;
            OperHotelGridView.ViewComp = model.ViewComp;
            OperHotelGridView.ViewExtraCost = model.ViewExtraCost;
            OperHotelGridView.ViewXLTDate = model.ViewXLTDate;
            OperHotelGridView.ViewDateFileReceived = model.ViewDateFileReceived;
            OperHotelGridView.ViewDateFileCompleted = model.ViewDateFileCompleted;
            OperHotelGridView.ViewDayOfArrival = model.ViewDayOfArrival;
            OperHotelGridView.ViewMonthOfArrival = model.ViewMonthOfArrival;
            OperHotelGridView.ViewClientBookingCode = model.ViewClientBookingCode;
            OperHotelGridView.ViewCheckInDate = model.ViewCheckInDate;
            OperHotelGridView.ViewCheckOutDate = model.ViewCheckOutDate;
            OperHotelGridView.ViewEstimatedNumberRooms = model.ViewEstimatedNumberRooms;
            OperHotelGridView.ViewEstimatedNumberPax = model.ViewEstimatedNumberPax;
            OperHotelGridView.ViewQuotaRoom = model.ViewQuotaRoom;
            OperHotelGridView.ViewQuotaRoomDiff = model.ViewQuotaRoomDiff;
            OperHotelGridView.ViewQuotaTax = model.ViewQuotaTax;
            OperHotelGridView.ViewQuotaOccTax = model.ViewQuotaOccTax;
            OperHotelGridView.ViewQuotaBrk = model.ViewQuotaBrk;
            OperHotelGridView.ViewQuotaLg = model.ViewQuotaLg;
            OperHotelGridView.ViewQuotaNight = model.ViewQuotaNight;
            OperHotelGridView.ViewQuotaVendorName = model.ViewQuotaVendorName;
            OperHotelGridView.ViewQuotaNote = model.ViewQuotaNote;
            OperHotelGridView.ViewConfirmed = model.ViewConfirmed;
            OperHotelGridView.ViewVendorName = model.ViewVendorName;
            OperHotelGridView.ViewVendorAddress = model.ViewVendorAddress;
            OperHotelGridView.ViewVendorPhone = model.ViewVendorPhone;
            OperHotelGridView.ViewVendorEmail = model.ViewVendorEmail;
            OperHotelGridView.ViewVendorContactName = model.ViewVendorContactName;
            OperHotelGridView.ViewVendorCity = model.ViewVendorCity;
            OperHotelGridView.ViewVendorTech = model.ViewVendorTech;
            OperHotelGridView.ViewVendorNote = model.ViewVendorNote;
            // init pageNum
            OperHotelGridView.HotelPageNumber = model.HotelPageNumber;
            // init all filter selected data
            // Group status filter
            if (model.SelectedFilterGroupStatus != null && !(model.IsRemoveGroupStatusFilter))
            {
                foreach (var filterGroupstatus in model.SelectedFilterGroupStatus)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterGroupStatus.Where(obj => obj.Id == filterGroupstatus).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelGroupStatus.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterGroupStatus = OperHotelGridView.HotelFilterGroupStatus.OrderByDescending(grpstatus => grpstatus.IsSelected).ToList();
            }
            // status filter
            if (model.SelectedFilterStatus != null && !(model.IsRemoveStatusFilter))
            {
                foreach (var filterstatus in model.SelectedFilterStatus)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterStatus.Where(obj => obj.Id == filterstatus).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelStatus.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterStatus = OperHotelGridView.HotelFilterStatus.OrderByDescending(vndstatus => vndstatus.IsSelected).ToList();
            }
            // Day of Arrival filter
            if (model.SelectedFilterDayofArrival != null && !(model.IsRemoveDayofArrivalFilter))
            {
                foreach (var filterdayofarr in model.SelectedFilterDayofArrival)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterDayofArrival.Where(obj => obj.Id == filterdayofarr).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelDayofArrival.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterDayofArrival = OperHotelGridView.HotelFilterDayofArrival.OrderByDescending(dayofarr => dayofarr.IsSelected).ToList();
            }
            // Month of Arrival filter
            if (model.SelectedFilterMonthofArrival != null && !(model.IsRemoveMonthofArrivalFilter))
            {
                foreach (var filterMonthofarr in model.SelectedFilterMonthofArrival)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterMonthofArrival.Where(obj => obj.Id == filterMonthofarr).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelMonthofArrival.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterMonthofArrival = OperHotelGridView.HotelFilterMonthofArrival.OrderByDescending(Monthofarr => Monthofarr.IsSelected).ToList();
            }
            // Arrival city filter
            if (model.SelectedFilterArrivalCity != null && !(model.IsRemoveArrivalCityFilter))
            {
                foreach (var filterarrcity in model.SelectedFilterArrivalCity)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterArrivalCity.Where(obj => obj.Id == filterarrcity).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelArrivalCity.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterArrivalCity = OperHotelGridView.HotelFilterArrivalCity.OrderByDescending(arrcity => arrcity.IsSelected).ToList();
            }
            // Estimated Number Rooms filter
            if (model.SelectedFilterEstNumberRoom != null && !(model.IsRemoveEstNumberRoomFilter))
            {
                foreach (var filterestnumberroom in model.SelectedFilterEstNumberRoom)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterEstNumberRoom.Where(obj => obj.Id == filterestnumberroom).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelEstNumberRoom.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterEstNumberRoom = OperHotelGridView.HotelFilterEstNumberRoom.OrderByDescending(estnumroom => estnumroom.IsSelected).ToList();
            }
            // Group Code filter
            if (model.SelectedFilterGroupCode != null && !(model.IsRemoveGroupCodeFilter))
            {
                foreach (var filterGroupCode in model.SelectedFilterGroupCode)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterGroupCode.Where(obj => obj.Id == filterGroupCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelGroupCode.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterGroupCode = OperHotelGridView.HotelFilterGroupCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Group Name filter
            if (model.SelectedFilterGroupName != null && !(model.IsRemoveGroupNameFilter))
            {
                foreach (var filterGroupName in model.SelectedFilterGroupName)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterGroupName.Where(obj => obj.Id == filterGroupName).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelGroupName.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterGroupName = OperHotelGridView.HotelFilterGroupName.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Customer filter
            if (model.SelectedFilterCustomerCode != null && !(model.IsRemoveCustomerCodeFilter))
            {
                foreach (var filtercust in model.SelectedFilterCustomerCode)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterCustomerCode.Where(obj => obj.Id == filtercust).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelCustomerCode.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterCustomerCode = OperHotelGridView.HotelFilterCustomerCode.OrderByDescending(cust => cust.IsSelected).ToList();
            }
            // Vendor Name filter
            if (model.SelectedFilterVendorName != null && !(model.IsRemoveVendorNameFilter))
            {
                foreach (var filtervenname in model.SelectedFilterVendorName)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterVendorName.Where(obj => obj.Id == filtervenname).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelVendorName.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterVendorName = OperHotelGridView.HotelFilterVendorName.OrderByDescending(vname => vname.IsSelected).ToList();
            }
            // Vendor City filter
            if (model.SelectedFilterVendorCity != null && !(model.IsRemoveVendorCityFilter))
            {
                foreach (var filtervenCity in model.SelectedFilterVendorCity)
                {
                    CheckBoxControlViewModel checkedItem = OperHotelGridView.HotelFilterVendorCity.Where(obj => obj.Id == filtervenCity).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperHotelGridView.HotelFilterSelVendorCity.Add(checkedItem);
                    }
                }
                OperHotelGridView.HotelFilterVendorCity = OperHotelGridView.HotelFilterVendorCity.OrderByDescending(vcity => vcity.IsSelected).ToList();
            }
        }
        private void OperationRoomInitModelState(OperationRoomGridViewModel OperRoomGridView, OperationRoomGridViewModel model)
        {
            // init all view elements
            OperRoomGridView.ViewRoomGroupName = model.ViewRoomGroupName;
            OperRoomGridView.ViewRoomGroupCode = model.ViewRoomGroupCode;
            OperRoomGridView.ViewRoomCustomer = model.ViewRoomCustomer;
            OperRoomGridView.ViewRoomPax = model.ViewRoomPax;
            OperRoomGridView.ViewRoomType = model.ViewRoomType;
            OperRoomGridView.ViewRoomPaxRoom = model.ViewRoomPaxRoom;
            OperRoomGridView.ViewRoomTitle = model.ViewRoomTitle;
            OperRoomGridView.ViewRoomNames = model.ViewRoomNames;
            OperRoomGridView.ViewRoomFullBoard = model.ViewRoomFullBoard;
            OperRoomGridView.ViewRoomFullBoardCount = model.ViewRoomFullBoardCount;
            OperRoomGridView.ViewRoomNotes = model.ViewRoomNotes;
            // init Search 
            OperRoomGridView.RoomGroupNameTxt = model.RoomGroupNameTxt;
            OperRoomGridView.RoomGroupCodeTxt = model.RoomGroupCodeTxt;
            OperRoomGridView.RoomCustomerTxt = model.RoomCustomerTxt;
            OperRoomGridView.RoomGroupIDTxt = model.RoomGroupIDTxt;
            OperRoomGridView.RoomGroupQuotaID = model.RoomGroupQuotaID;
            // init pageNum
            OperRoomGridView.RoomPageNumber = model.RoomPageNumber;
            // init all filter selected data
            // Room Type filter
            if (model.SelectedRoomFilterRoomType != null && !(model.RoomIsRemoveRoomTypeFilter))
                foreach (var type in model.SelectedRoomFilterRoomType)
                {
                    CheckBoxControlViewModel checkedItem = OperRoomGridView.RoomFilterRoomType.Where(obj => obj.Id == type).FirstOrDefault();
                    if (checkedItem != null)
                        OperRoomGridView.RoomFilterSelRoomType.Add(checkedItem);
                }
            // Room Title filter
            if (model.SelectedRoomFilterRoomTitle != null && !(model.RoomIsRemoveRoomTitleFilter))
                foreach (var title in model.SelectedRoomFilterRoomTitle)
                {
                    CheckBoxControlViewModel checkedItem = OperRoomGridView.RoomFilterRoomTitle.Where(obj => obj.Id == title).FirstOrDefault();
                    if (checkedItem != null)
                        OperRoomGridView.RoomFilterSelRoomTitle.Add(checkedItem);
                }
            // Customer filter
            if (model.SelectedRoomFilterCustomer != null && !(model.RoomIsRemoveCustomerCodeFilter))
                foreach (var filtercust in model.SelectedRoomFilterCustomer)
                {
                    CheckBoxControlViewModel checkedItem = OperRoomGridView.RoomFilterCustomer.Where(obj => obj.Id == filtercust).FirstOrDefault();
                    if (checkedItem != null)
                        OperRoomGridView.RoomFilterSelCustomer.Add(checkedItem);
                }
        }
        private void OperationGroupCheckListInitModelState(OperationGroupCheckListGridViewModel OperGroupCheckListGridView, OperationGroupCheckListGridViewModel model)
        {
            // init Scrolls
            OperGroupCheckListGridView.GroupCheckListLeftScrollPossition = model.GroupCheckListLeftScrollPossition;
            OperGroupCheckListGridView.GroupCheckListTopScrollPossition = model.GroupCheckListTopScrollPossition;
            // init search part elements
            OperGroupCheckListGridView.GroupCheckListSearchCustomer = model.GroupCheckListSearchCustomer;
            OperGroupCheckListGridView.GroupCheckListSearchGroupCode = model.GroupCheckListSearchGroupCode;
            OperGroupCheckListGridView.GroupCheckListSearchGroupName = model.GroupCheckListSearchGroupName;
            OperGroupCheckListGridView.GroupCheckListSearchSelectedIsGir = model.GroupCheckListSearchSelectedIsGir;
            // init all view elements
            OperGroupCheckListGridView.ViewGroupCheckListGroupCode = model.ViewGroupCheckListGroupCode;
            OperGroupCheckListGridView.ViewGroupCheckListGroupName = model.ViewGroupCheckListGroupName;
            OperGroupCheckListGridView.ViewGroupCheckListCustomer = model.ViewGroupCheckListCustomer;
            OperGroupCheckListGridView.ViewGroupCheckListPax = model.ViewGroupCheckListPax;
            OperGroupCheckListGridView.ViewGroupCheckListIsGir = model.ViewGroupCheckListIsGir;
            OperGroupCheckListGridView.ViewGroupCheckListMonthOfArrival = model.ViewGroupCheckListMonthOfArrival;
            OperGroupCheckListGridView.ViewGroupCheckListHotelStatus = model.ViewGroupCheckListHotelStatus;
            OperGroupCheckListGridView.ViewGroupCheckListHotelNotes = model.ViewGroupCheckListHotelNotes;
            OperGroupCheckListGridView.ViewGroupCheckListBusGuideNotes = model.ViewGroupCheckListBusGuideNotes;
            OperGroupCheckListGridView.ViewGroupCheckListArrivalDate = model.ViewGroupCheckListArrivalDate;
            OperGroupCheckListGridView.ViewGroupCheckListDepartureDate = model.ViewGroupCheckListDepartureDate;
            OperGroupCheckListGridView.ViewGroupCheckListArrivalCity = model.ViewGroupCheckListArrivalCity;
            OperGroupCheckListGridView.ViewGroupCheckListDepartureCity = model.ViewGroupCheckListDepartureCity;
            
            // init pageNum
            OperGroupCheckListGridView.GroupCheckListPageNumber = model.GroupCheckListPageNumber;
            // init all filter selected data
            // GroupCheckList Group Code filter
            if (model.SelectedGroupCheckListFilterGroupCode != null && !(model.IsRemoveGroupCheckListGroupCodeFilter))
            {
                foreach (var filterGroupCode in model.SelectedGroupCheckListFilterGroupCode)
                {
                    CheckBoxControlViewModel checkedItem = OperGroupCheckListGridView.GroupCheckListFilterGroupCode.Where(obj => obj.Id == filterGroupCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperGroupCheckListGridView.GroupCheckListFilterSelGroupCode.Add(checkedItem);
                    }
                }
                OperGroupCheckListGridView.GroupCheckListFilterGroupCode = OperGroupCheckListGridView.GroupCheckListFilterGroupCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // GroupCheckList Group Name filter
            if (model.SelectedGroupCheckListFilterGroupName != null && !(model.IsRemoveGroupCheckListGroupNameFilter))
            {
                foreach (var filterGroupName in model.SelectedGroupCheckListFilterGroupName)
                {
                    CheckBoxControlViewModel checkedItem = OperGroupCheckListGridView.GroupCheckListFilterGroupName.Where(obj => obj.Id == filterGroupName).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperGroupCheckListGridView.GroupCheckListFilterSelGroupName.Add(checkedItem);
                    }
                }
                OperGroupCheckListGridView.GroupCheckListFilterGroupName = OperGroupCheckListGridView.GroupCheckListFilterGroupName.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // GroupCheckList Customer filter
            if (model.SelectedGroupCheckListFilterCustomerCode != null && !(model.IsRemoveGroupCheckListCustomerCodeFilter))
            {
                foreach (var filterCustomerCode in model.SelectedGroupCheckListFilterCustomerCode)
                {
                    CheckBoxControlViewModel checkedItem = OperGroupCheckListGridView.GroupCheckListFilterCustomerCode.Where(obj => obj.Id == filterCustomerCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperGroupCheckListGridView.GroupCheckListFilterSelCustomerCode.Add(checkedItem);
                    }
                }
                OperGroupCheckListGridView.GroupCheckListFilterCustomerCode = OperGroupCheckListGridView.GroupCheckListFilterCustomerCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
        }
        private void OperationAttractionsInitModelState(OperationAttractionsGridViewModel OperAttractionsGridView, OperationAttractionsGridViewModel model, double? Count)
        {
            OperAttractionsGridView.AttractionsCount = (model.AttractionsPageNumber == 0 ? "1" : model.AttractionsPageNumber.ToString()) + " of " + (Count != null ? ((int)Math.Ceiling((double)Count / (double)OperationBusGridBData.TakeCount)).ToString() : "1");
            OperAttractionsGridView.AttractionsCountCheck = Count != null ? ((int)Math.Ceiling((double)Count / (double)OperationAttractionsGridBData.TakeCount)) : 1;
            // init Scrolls
            OperAttractionsGridView.AttractionsLeftScrollPossition = model.AttractionsLeftScrollPossition;
            OperAttractionsGridView.AttractionsTopScrollPossition = model.AttractionsTopScrollPossition;
            // init search part elements
            OperAttractionsGridView.AttractionsSearchStartFromDate = model.AttractionsSearchStartFromDate;
            OperAttractionsGridView.AttractionsSearchStartToDate = model.AttractionsSearchStartToDate;
            OperAttractionsGridView.AttractionsSearchCustomer = model.AttractionsSearchCustomer;
            OperAttractionsGridView.AttractionsSearchGroupCode = model.AttractionsSearchGroupCode;
            OperAttractionsGridView.AttractionsSearchGroupName = model.AttractionsSearchGroupName;
            OperAttractionsGridView.AttractionsSearchVendorName = model.AttractionsSearchVendorName;
            OperAttractionsGridView.AttractionsSearchEmployee = model.AttractionsSearchEmployee;
            // init all view elements
            OperAttractionsGridView.ViewAttractionsIsGuideInvoice = model.ViewAttractionsIsGuideInvoice;
            OperAttractionsGridView.ViewAttractionsGuideInvoicePrice = model.ViewAttractionsGuideInvoicePrice;
            OperAttractionsGridView.ViewAttractionsIsInvoice = model.ViewAttractionsIsInvoice;
            OperAttractionsGridView.ViewAttractionsInvoicePrice = model.ViewAttractionsInvoicePrice;
            OperAttractionsGridView.ViewAttractionsOptionalHtml = model.ViewAttractionsOptionalHtml;
            OperAttractionsGridView.ViewAttractionsGroupCode = model.ViewAttractionsGroupCode;
            OperAttractionsGridView.ViewAttractionsConfHtml = model.ViewAttractionsConfHtml;
            OperAttractionsGridView.ViewAttractionsGroupName = model.ViewAttractionsGroupName;
            OperAttractionsGridView.ViewAttractionsCustomer = model.ViewAttractionsCustomer;
            OperAttractionsGridView.ViewAttractionsPax = model.ViewAttractionsPax;
            OperAttractionsGridView.ViewAttractionsEmployee = model.ViewAttractionsEmployee;
            OperAttractionsGridView.ViewAttractionsEstNumberofPerson = model.ViewAttractionsEstNumberofPerson;
            OperAttractionsGridView.ViewAttractionsSupplier = model.ViewAttractionsSupplier;
            OperAttractionsGridView.ViewAttractionsStatus = model.ViewAttractionsStatus;
            OperAttractionsGridView.ViewAttractionsRestService = model.ViewAttractionsRestService;
            OperAttractionsGridView.ViewAttractionsCurrency = model.ViewAttractionsCurrency;
            OperAttractionsGridView.ViewAttractionsQuotaPrice = model.ViewAttractionsQuotaPrice;
            OperAttractionsGridView.ViewAttractionsQuotaSupplier = model.ViewAttractionsQuotaSupplier;
            OperAttractionsGridView.ViewAttractionsDifference = model.ViewAttractionsDifference;
            OperAttractionsGridView.ViewAttractionsDone = model.ViewAttractionsDone;
            OperAttractionsGridView.ViewAttractionsDate = model.ViewAttractionsDate;
            OperAttractionsGridView.ViewAttractionsTime = model.ViewAttractionsTime;
            OperAttractionsGridView.ViewAttractionsCategory = model.ViewAttractionsCategory;
            OperAttractionsGridView.ViewAttractionsType = model.ViewAttractionsType;
            OperAttractionsGridView.ViewAttractionsFirstPayment = model.ViewAttractionsFirstPayment;
            OperAttractionsGridView.ViewAttractionsSelectedFirstPaymentMethod = model.ViewAttractionsSelectedFirstPaymentMethod;
            OperAttractionsGridView.ViewAttractionsDateFirstPayment = model.ViewAttractionsDateFirstPayment;
            OperAttractionsGridView.ViewAttractionsSecondPayment = model.ViewAttractionsSecondPayment;
            OperAttractionsGridView.ViewAttractionsSelectedSecondPaymentMethod = model.ViewAttractionsSelectedSecondPaymentMethod;
            OperAttractionsGridView.ViewAttractionsDateSecondPayment = model.ViewAttractionsDateSecondPayment;
            OperAttractionsGridView.ViewAttractionsThirdPayment = model.ViewAttractionsThirdPayment;
            OperAttractionsGridView.ViewAttractionsSelectedThirdPaymentMethod = model.ViewAttractionsSelectedThirdPaymentMethod;
            OperAttractionsGridView.ViewAttractionsDateThirdPayment = model.ViewAttractionsDateThirdPayment;
            OperAttractionsGridView.ViewAttractionsUnitRate = model.ViewAttractionsUnitRate;
            OperAttractionsGridView.ViewAttractionsOutstandingAmt = model.ViewAttractionsOutstandingAmt;
            OperAttractionsGridView.ViewAttractionsDeposit = model.ViewAttractionsDeposit;
            OperAttractionsGridView.ViewAttractionsDepositDate = model.ViewAttractionsDepositDate;
            OperAttractionsGridView.ViewAttractionsContact = model.ViewAttractionsContact;
            OperAttractionsGridView.ViewAttractionsPhone = model.ViewAttractionsPhone;
            OperAttractionsGridView.ViewAttractionsEmail = model.ViewAttractionsEmail;
            OperAttractionsGridView.ViewAttractionsAddress = model.ViewAttractionsAddress;
            OperAttractionsGridView.ViewAttractionsCity = model.ViewAttractionsCity;
            OperAttractionsGridView.ViewAttractionsState = model.ViewAttractionsState;
            OperAttractionsGridView.ViewAttractionsTotalCost = model.ViewAttractionsTotalCost;
            OperAttractionsGridView.ViewAttractionsTotalAmountPaid = model.ViewAttractionsTotalAmountPaid;
            OperAttractionsGridView.ViewAttractionsFinalPayment = model.ViewAttractionsFinalPayment;
            OperAttractionsGridView.ViewAttractionsDepositAmountPaid = model.ViewAttractionsDepositAmountPaid;
            OperAttractionsGridView.ViewAttractionsCreditCardChargeAmount = model.ViewAttractionsCreditCardChargeAmount;
            OperAttractionsGridView.ViewAttractionsCreditCardMemo = model.ViewAttractionsCreditCardMemo;
            OperAttractionsGridView.ViewAttractionsDifferenceTotalPaid_TotalCharged = model.ViewAttractionsDifferenceTotalPaid_TotalCharged;
            // init pageNum
            OperAttractionsGridView.AttractionsPageNumber = model.AttractionsPageNumber;
            // init all filter selected data
            // Attractions Group Code filter
            if (model.SelectedAttractionsFilterGroupCode != null && !(model.IsRemoveAttractionsGroupCodeFilter))
            {
                foreach (var filterGroupCode in model.SelectedAttractionsFilterGroupCode)
                {
                    CheckBoxControlViewModel checkedItem = OperAttractionsGridView.AttractionsFilterGroupCode.Where(obj => obj.Id == filterGroupCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperAttractionsGridView.AttractionsFilterSelGroupCode.Add(checkedItem);
                    }
                }
                OperAttractionsGridView.AttractionsFilterGroupCode = OperAttractionsGridView.AttractionsFilterGroupCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Attractions Group Name filter
            if (model.SelectedAttractionsFilterGroupName != null && !(model.IsRemoveAttractionsGroupNameFilter))
            {
                foreach (var filterGroupName in model.SelectedAttractionsFilterGroupName)
                {
                    CheckBoxControlViewModel checkedItem = OperAttractionsGridView.AttractionsFilterGroupName.Where(obj => obj.Id == filterGroupName).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperAttractionsGridView.AttractionsFilterSelGroupName.Add(checkedItem);
                    }
                }
                OperAttractionsGridView.AttractionsFilterGroupName = OperAttractionsGridView.AttractionsFilterGroupName.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Attractions Customer filter
            if (model.SelectedAttractionsFilterCustomerCode != null && !(model.IsRemoveAttractionsCustomerCodeFilter))
            {
                foreach (var filterCustomerCode in model.SelectedAttractionsFilterCustomerCode)
                {
                    CheckBoxControlViewModel checkedItem = OperAttractionsGridView.AttractionsFilterCustomerCode.Where(obj => obj.Id == filterCustomerCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperAttractionsGridView.AttractionsFilterSelCustomerCode.Add(checkedItem);
                    }
                }
                OperAttractionsGridView.AttractionsFilterCustomerCode = OperAttractionsGridView.AttractionsFilterCustomerCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Attractions Status filter
            if (model.SelectedAttractionsFilterStatus != null && !(model.IsRemoveAttractionsStatusFilter))
            {
                foreach (var filterStatus in model.SelectedAttractionsFilterStatus)
                {
                    CheckBoxControlViewModel checkedItem = OperAttractionsGridView.AttractionsFilterStatus.Where(obj => obj.Id == filterStatus).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperAttractionsGridView.AttractionsFilterSelStatus.Add(checkedItem);
                    }
                }
                OperAttractionsGridView.AttractionsFilterStatus = OperAttractionsGridView.AttractionsFilterStatus.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Attractions Vendor Name filter
            if (model.SelectedAttractionsFilterVendorName != null && !(model.IsRemoveAttractionsVendorNameFilter))
            {
                foreach (var filterVendorName in model.SelectedAttractionsFilterVendorName)
                {
                    CheckBoxControlViewModel checkedItem = OperAttractionsGridView.AttractionsFilterVendorName.Where(obj => obj.Id == filterVendorName).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperAttractionsGridView.AttractionsFilterSelVendorName.Add(checkedItem);
                    }
                }
                OperAttractionsGridView.AttractionsFilterVendorName = OperAttractionsGridView.AttractionsFilterVendorName.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Attractions Vendor Type filter
            if (model.SelectedAttractionsFilterVendorType != null && !(model.IsRemoveAttractionsVendorTypeFilter))
            {
                foreach (var filterVendorType in model.SelectedAttractionsFilterVendorType)
                {
                    CheckBoxControlViewModel checkedItem = OperAttractionsGridView.AttractionsFilterVendorType.Where(obj => obj.Id == filterVendorType).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperAttractionsGridView.AttractionsFilterSelVendorType.Add(checkedItem);
                    }
                }
                OperAttractionsGridView.AttractionsFilterVendorType = OperAttractionsGridView.AttractionsFilterVendorType.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Vendor City filter
            if (model.SelectedAttractionsFilterVendorCity != null && !(model.IsRemoveAttractionsVendorCityFilter))
            {
                foreach (var filtervenCity in model.SelectedAttractionsFilterVendorCity)
                {
                    CheckBoxControlViewModel checkedItem = OperAttractionsGridView.AttractionsFilterVendorCity.Where(obj => obj.Id == filtervenCity).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperAttractionsGridView.AttractionsFilterSelVendorCity.Add(checkedItem);
                    }
                }
                OperAttractionsGridView.AttractionsFilterVendorCity = OperAttractionsGridView.AttractionsFilterVendorCity.OrderByDescending(vcity => vcity.IsSelected).ToList();
            }
            // Restaurant Type filter
            if (model.SelectedAttractionsFilterRestaurantType != null && !(model.IsRemoveAttractionsRestaurantTypeFilter))
            {
                foreach (var filterresttype in model.SelectedAttractionsFilterRestaurantType)
                {
                    CheckBoxControlViewModel checkedItem = OperAttractionsGridView.AttractionsFilterRestaurantType.Where(obj => obj.Id == filterresttype).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperAttractionsGridView.AttractionsFilterSelRestaurantType.Add(checkedItem);
                    }
                }
                OperAttractionsGridView.AttractionsFilterRestaurantType = OperAttractionsGridView.AttractionsFilterRestaurantType.OrderByDescending(vcity => vcity.IsSelected).ToList();
            }
        }
        private void OperationMiscInitModelState(OperationMiscGridViewModel OperMiscGridView, OperationMiscGridViewModel model, double? Count)
        {
            OperMiscGridView.MiscCount = (model.MiscPageNumber == 0 ? "1" : model.MiscPageNumber.ToString()) + " of " + (Count != null ? ((int)Math.Ceiling((double)Count / (double)OperationMiscGridBData.TakeCount)).ToString() : "1");
            OperMiscGridView.MiscCountCheck = Count != null ? ((int)Math.Ceiling((double)Count / (double)OperationMiscGridBData.TakeCount)) : 1;
            // init Scrolls
            OperMiscGridView.MiscLeftScrollPossition = model.MiscLeftScrollPossition;
            OperMiscGridView.MiscTopScrollPossition = model.MiscTopScrollPossition;
            // init search part elements
            OperMiscGridView.MiscSearchStartFromDate = model.MiscSearchStartFromDate;
            OperMiscGridView.MiscSearchStartToDate = model.MiscSearchStartToDate;
            OperMiscGridView.MiscSearchCustomer = model.MiscSearchCustomer;
            OperMiscGridView.MiscSearchGroupCode = model.MiscSearchGroupCode;
            OperMiscGridView.MiscSearchGroupName = model.MiscSearchGroupName;
            OperMiscGridView.MiscSearchVendorName = model.MiscSearchVendorName;
            OperMiscGridView.MiscSearchEmployeeID = model.MiscSearchEmployeeID;
            OperMiscGridView.MiscSearchEmployee = model.MiscSearchEmployee;
            // init all view elements
            OperMiscGridView.ViewMiscPlane = model.ViewMiscPlane;
            OperMiscGridView.ViewMiscIsComp = model.ViewMiscIsComp;
            OperMiscGridView.ViewMiscGroupCode = model.ViewMiscGroupCode;
            OperMiscGridView.ViewMiscConfHtml = model.ViewMiscConfHtml;
            OperMiscGridView.ViewMiscGroupName = model.ViewMiscGroupName;
            OperMiscGridView.ViewMiscCustomer = model.ViewMiscCustomer;
            OperMiscGridView.ViewMiscEmployee = model.ViewMiscEmployee;
            OperMiscGridView.ViewMiscServiceDetail = model.ViewMiscServiceDetail;
            OperMiscGridView.ViewMiscPax = model.ViewMiscPax;
            OperMiscGridView.ViewMiscEstNumberofPerson = model.ViewMiscEstNumberofPerson;
            OperMiscGridView.ViewMiscSupplier = model.ViewMiscSupplier;
            OperMiscGridView.ViewMiscStatus = model.ViewMiscStatus;
            OperMiscGridView.ViewMiscCurrency = model.ViewMiscCurrency;
            OperMiscGridView.ViewMiscTotalAmountPaid = model.ViewMiscTotalAmountPaid;
            OperMiscGridView.ViewMiscTotalCost = model.ViewMiscTotalCost;
            OperMiscGridView.ViewMiscOutstandingAmt = model.ViewMiscOutstandingAmt;
            OperMiscGridView.ViewMiscFirstPayment = model.ViewMiscFirstPayment;
            OperMiscGridView.ViewMiscSelectedFirstPaymentMethod = model.ViewMiscSelectedFirstPaymentMethod;
            OperMiscGridView.ViewMiscDateFirstPayment = model.ViewMiscDateFirstPayment;
            OperMiscGridView.ViewMiscSecondPayment = model.ViewMiscSecondPayment;
            OperMiscGridView.ViewMiscSelectedSecondPaymentMethod = model.ViewMiscSelectedSecondPaymentMethod;
            OperMiscGridView.ViewMiscDateSecondPayment = model.ViewMiscDateSecondPayment;
            OperMiscGridView.ViewMiscThirdPayment = model.ViewMiscThirdPayment;
            OperMiscGridView.ViewMiscSelectedThirdPaymentMethod = model.ViewMiscSelectedThirdPaymentMethod;
            OperMiscGridView.ViewMiscDateThirdPayment = model.ViewMiscDateThirdPayment;
            OperMiscGridView.ViewMiscQuotaPrice = model.ViewMiscQuotaPrice;
            OperMiscGridView.ViewMiscQuotaPerGroupPrice = model.ViewMiscQuotaPerGroupPrice;
            OperMiscGridView.ViewMiscQuotaSupplier = model.ViewMiscQuotaSupplier;
            OperMiscGridView.ViewMiscDate = model.ViewMiscDate;
            OperMiscGridView.ViewMiscTime = model.ViewMiscTime;
            OperMiscGridView.ViewMiscUnitPrice = model.ViewMiscUnitPrice;
            OperMiscGridView.ViewMiscUnitPricePG = model.ViewMiscUnitPricePG;
            OperMiscGridView.ViewMiscDiff = model.ViewMiscDiff;
            OperMiscGridView.ViewMiscPGDiff = model.ViewMiscPGDiff;
            OperMiscGridView.ViewMiscContact = model.ViewMiscContact;
            OperMiscGridView.ViewMiscPhone = model.ViewMiscPhone;
            OperMiscGridView.ViewMiscEmail = model.ViewMiscEmail;
            OperMiscGridView.ViewMiscAddress = model.ViewMiscAddress;
            OperMiscGridView.ViewMiscCity = model.ViewMiscCity;
            OperMiscGridView.ViewMiscNotes = model.ViewMiscNotes;
            // init pageNum
            OperMiscGridView.MiscPageNumber = model.MiscPageNumber;
            // init all filter selected data
            // Misc Group Code filter
            if (model.SelectedMiscFilterGroupCode != null && !(model.IsRemoveMiscGroupCodeFilter))
            {
                foreach (var filterGroupCode in model.SelectedMiscFilterGroupCode)
                {
                    CheckBoxControlViewModel checkedItem = OperMiscGridView.MiscFilterGroupCode.Where(obj => obj.Id == filterGroupCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperMiscGridView.MiscFilterSelGroupCode.Add(checkedItem);
                    }
                }
                OperMiscGridView.MiscFilterGroupCode = OperMiscGridView.MiscFilterGroupCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Misc Group Name filter
            if (model.SelectedMiscFilterGroupName != null && !(model.IsRemoveMiscGroupNameFilter))
            {
                foreach (var filterGroupName in model.SelectedMiscFilterGroupName)
                {
                    CheckBoxControlViewModel checkedItem = OperMiscGridView.MiscFilterGroupName.Where(obj => obj.Id == filterGroupName).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperMiscGridView.MiscFilterSelGroupName.Add(checkedItem);
                    }
                }
                OperMiscGridView.MiscFilterGroupName = OperMiscGridView.MiscFilterGroupName.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Misc Customer filter
            if (model.SelectedMiscFilterCustomerCode != null && !(model.IsRemoveMiscCustomerCodeFilter))
            {
                foreach (var filterCustomerCode in model.SelectedMiscFilterCustomerCode)
                {
                    CheckBoxControlViewModel checkedItem = OperMiscGridView.MiscFilterCustomerCode.Where(obj => obj.Id == filterCustomerCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperMiscGridView.MiscFilterSelCustomerCode.Add(checkedItem);
                    }
                }
                OperMiscGridView.MiscFilterCustomerCode = OperMiscGridView.MiscFilterCustomerCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Misc Status filter
            if (model.SelectedMiscFilterStatus != null && !(model.IsRemoveMiscStatusFilter))
            {
                foreach (var filterStatus in model.SelectedMiscFilterStatus)
                {
                    CheckBoxControlViewModel checkedItem = OperMiscGridView.MiscFilterStatus.Where(obj => obj.Id == filterStatus).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperMiscGridView.MiscFilterSelStatus.Add(checkedItem);
                    }
                }
                OperMiscGridView.MiscFilterStatus = OperMiscGridView.MiscFilterStatus.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Misc Vendor Name filter
            if (model.SelectedMiscFilterVendorName != null && !(model.IsRemoveMiscVendorNameFilter))
            {
                foreach (var filterVendorName in model.SelectedMiscFilterVendorName)
                {
                    CheckBoxControlViewModel checkedItem = OperMiscGridView.MiscFilterVendorName.Where(obj => obj.Id == filterVendorName).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperMiscGridView.MiscFilterSelVendorName.Add(checkedItem);
                    }
                }
                OperMiscGridView.MiscFilterVendorName = OperMiscGridView.MiscFilterVendorName.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Vendor City filter
            if (model.SelectedMiscFilterVendorCity != null && !(model.IsRemoveMiscVendorCityFilter))
            {
                foreach (var filtervenCity in model.SelectedMiscFilterVendorCity)
                {
                    CheckBoxControlViewModel checkedItem = OperMiscGridView.MiscFilterVendorCity.Where(obj => obj.Id == filtervenCity).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperMiscGridView.MiscFilterSelVendorCity.Add(checkedItem);
                    }
                }
                OperMiscGridView.MiscFilterVendorCity = OperMiscGridView.MiscFilterVendorCity.OrderByDescending(vcity => vcity.IsSelected).ToList();
            }
        }
        private void OperationTechProgInitModelState(OperationTechProgGridViewModel OperTechProgGridView, OperationTechProgGridViewModel model)
        {
            OperTechProgGridView.TechProgSearchGroupCode = model.TechProgSearchGroupCode;
            // init all view elements
            OperTechProgGridView.ViewTechProgDay = model.ViewTechProgDay;
            OperTechProgGridView.ViewTechProgPrn = model.ViewTechProgPrn;
            OperTechProgGridView.ViewTechProgDate = model.ViewTechProgDate;
            OperTechProgGridView.ViewTechProgTime = model.ViewTechProgTime;
            OperTechProgGridView.ViewTechProgDetail = model.ViewTechProgDetail;
            OperTechProgGridView.ViewTechProgDescription = model.ViewTechProgDescription;
            OperTechProgGridView.ViewTechProgVia = model.ViewTechProgVia;
            OperTechProgGridView.ViewTechProgType = model.ViewTechProgType;
            OperTechProgGridView.ViewTechProgVendorName = model.ViewTechProgVendorName;
            OperTechProgGridView.ViewTechProgVendorAddress = model.ViewTechProgVendorAddress;
            OperTechProgGridView.ViewTechProgVendorEmail = model.ViewTechProgVendorEmail;
            OperTechProgGridView.ViewTechProgGuideName = model.ViewTechProgGuideName;
            OperTechProgGridView.ViewTechProgGuidePhone = model.ViewTechProgGuidePhone;
            OperTechProgGridView.ViewTechProgCity = model.ViewTechProgCity;
            OperTechProgGridView.ViewTechProgArea = model.ViewTechProgArea;

            // Type filter
            if (model.SelectedTechProgFilterType != null && !(model.TechProgIsRemoveTypeFilter))
            {
                foreach (var filtertype in model.SelectedTechProgFilterType)
                {
                    CheckBoxControlViewModel checkedItem = OperTechProgGridView.TechProgFilterType.Where(obj => obj.Id == filtertype).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperTechProgGridView.TechProgFilterSelType.Add(checkedItem);
                    }
                }
                OperTechProgGridView.TechProgFilterType = OperTechProgGridView.TechProgFilterType.OrderByDescending(vcity => vcity.IsSelected).ToList();
            }
        }
        private void OperationBusInitModelState(OperationBusGridViewModel OperBusGridView, OperationBusGridViewModel model, double? Count)
        {
            OperBusGridView.BusCount = (model.BusPageNumber == 0 ? "1" : model.BusPageNumber.ToString()) + " of " + (Count != null ? ((int)Math.Ceiling((double)Count / (double)OperationBusGridBData.TakeCount)).ToString() : "1");
            OperBusGridView.BusCountCheck = Count != null ? ((int)Math.Ceiling((double)Count / (double)OperationBusGridBData.TakeCount)) : 1;
            // init Scrolls
            OperBusGridView.BusLeftScrollPossition = model.BusLeftScrollPossition;
            OperBusGridView.BusTopScrollPossition = model.BusTopScrollPossition;
            // init search part elements
            OperBusGridView.BusSearchStartFromDate = model.BusSearchStartFromDate;
            OperBusGridView.BusSearchStartToDate = model.BusSearchStartToDate;
            OperBusGridView.BusSearchStartCity = model.BusSearchStartCity;
            OperBusGridView.BusSearchEndCity = model.BusSearchEndCity;
            OperBusGridView.BusSearchCustomer = model.BusSearchCustomer;
            OperBusGridView.BusSearchGuideName = model.BusSearchGuideName;
            OperBusGridView.BusSearchGroupCode = model.BusSearchGroupCode;
            OperBusGridView.BusSearchGroupName = model.BusSearchGroupName;
            OperBusGridView.BusSearchVendorName = model.BusSearchVendorName;
            OperBusGridView.BusSearchEmployeeID = model.BusSearchEmployeeID;
            OperBusGridView.BusSearchEmployee = model.BusSearchEmployee;
            // init all view elements
            OperBusGridView.ViewBusIsInvoice = model.ViewBusIsInvoice;
            OperBusGridView.ViewBusInvoicePrice = model.ViewBusInvoicePrice;
            OperBusGridView.ViewBusGroupCode = model.ViewBusGroupCode;
            OperBusGridView.ViewBusGroupName = model.ViewBusGroupName;
            OperBusGridView.ViewBusCustomer = model.ViewBusCustomer;
            OperBusGridView.ViewBusPax = model.ViewBusPax;
            OperBusGridView.ViewBusEstNumberofPerson = model.ViewBusEstNumberofPerson;
            OperBusGridView.ViewBusCost = model.ViewBusCost;
            OperBusGridView.ViewBusConfHtml = model.ViewBusConfHtml;
            OperBusGridView.ViewBusEmployee = model.ViewBusEmployee;
            OperBusGridView.ViewBusGuideTotalPaid = model.ViewBusGuideTotalPaid;
            OperBusGridView.ViewBusBusTotalPaid = model.ViewBusBusTotalPaid;
            OperBusGridView.ViewBusGuideDifference = model.ViewBusGuideDifference;
            OperBusGridView.ViewBusGuideMiscDifference = model.ViewBusGuideMiscDifference;
            OperBusGridView.ViewBusGuideStepOnDifference = model.ViewBusGuideStepOnDifference;
            OperBusGridView.ViewBusBusDifference = model.ViewBusBusDifference;
            OperBusGridView.ViewBusStart = model.ViewBusStart;
            OperBusGridView.ViewBusTime = model.ViewBusTime;
            OperBusGridView.ViewBusDateOfService = model.ViewBusDateOfService;
            OperBusGridView.ViewBusStartCity = model.ViewBusStartCity;
            OperBusGridView.ViewBusEndCity = model.ViewBusEndCity;
            OperBusGridView.ViewBusBusCount = model.ViewBusBusCount;
            OperBusGridView.ViewBusBusSize = model.ViewBusBusSize;
            OperBusGridView.ViewBusServiceCode = model.ViewBusServiceCode;
            OperBusGridView.ViewBusServiceDetail = model.ViewBusServiceDetail;
            OperBusGridView.ViewBusSupplier = model.ViewBusSupplier;
            OperBusGridView.ViewBusAirport = model.ViewBusAirport;
            OperBusGridView.ViewBusStatus = model.ViewBusStatus;
            OperBusGridView.ViewBusConfirmation = model.ViewBusConfirmation;
            OperBusGridView.ViewBusGuide = model.ViewBusGuide;
            OperBusGridView.ViewBusGuideSalary = model.ViewBusGuideSalary;
            OperBusGridView.ViewBusGuideMisc = model.ViewBusGuideMisc;
            OperBusGridView.ViewBusGuideStepOn = model.ViewBusGuideStepOn;
            OperBusGridView.ViewBusBusCurrency = model.ViewBusBusCurrency;
            OperBusGridView.ViewBusQuotaBusPrice = model.ViewBusQuotaBusPrice;
            OperBusGridView.ViewBusQuotaSupplier = model.ViewBusQuotaSupplier;
            OperBusGridView.ViewBusGuideCurrency = model.ViewBusGuideCurrency;
            OperBusGridView.ViewBusQuotaGuideSalary = model.ViewBusQuotaGuideSalary;
            OperBusGridView.ViewBusQuotaGuideMisc = model.ViewBusQuotaGuideMisc;
            OperBusGridView.ViewBusQuotaGuideStepOn = model.ViewBusQuotaGuideStepOn;
            OperBusGridView.ViewBusQuotaGuide = model.ViewBusQuotaGuide;
            OperBusGridView.ViewBusGuideSalaryPaid = model.ViewBusGuideSalaryPaid;
            OperBusGridView.ViewBusGuideAdditionalCharges = model.ViewBusGuideAdditionalCharges;
            OperBusGridView.ViewBusGuideSalaryInvoicePaid = model.ViewBusGuideSalaryInvoicePaid;
            OperBusGridView.ViewBusGuideTotalCost = model.ViewBusGuideTotalCost;
            OperBusGridView.ViewBusBusTotalCost = model.ViewBusBusTotalCost;
            OperBusGridView.ViewBusPrice = model.ViewBusPrice;
            OperBusGridView.ViewBusFirstPayment = model.ViewBusFirstPayment;
            OperBusGridView.ViewBusSelectedFirstPaymentMethod = model.ViewBusSelectedFirstPaymentMethod;
            OperBusGridView.ViewBusDateFirstPayment = model.ViewBusDateFirstPayment;
            OperBusGridView.ViewBusSecondPayment = model.ViewBusSecondPayment;
            OperBusGridView.ViewBusSelectedSecondPaymentMethod = model.ViewBusSelectedSecondPaymentMethod;
            OperBusGridView.ViewBusDateSecondPayment = model.ViewBusDateSecondPayment;  
            OperBusGridView.ViewBusThirdPayment = model.ViewBusThirdPayment; 
            OperBusGridView.ViewBusSelectedThirdPaymentMethod = model.ViewBusSelectedThirdPaymentMethod;
            OperBusGridView.ViewBusDateThirdPayment = model.ViewBusDateThirdPayment;
            OperBusGridView.ViewBusGuideFirstPayment = model.ViewBusGuideFirstPayment;
            OperBusGridView.ViewBusGuideSelectedFirstPaymentMethod = model.ViewBusGuideSelectedFirstPaymentMethod;
            OperBusGridView.ViewBusGuideDateFirstPayment = model.ViewBusGuideDateFirstPayment;
            OperBusGridView.ViewBusGuideSecondPayment = model.ViewBusGuideSecondPayment;
            OperBusGridView.ViewBusGuideSelectedSecondPaymentMethod = model.ViewBusGuideSelectedSecondPaymentMethod;
            OperBusGridView.ViewBusGuideDateSecondPayment = model.ViewBusGuideDateSecondPayment;
            OperBusGridView.ViewBusGuideThirdPayment = model.ViewBusGuideThirdPayment;
            OperBusGridView.ViewBusGuideSelectedThirdPaymentMethod = model.ViewBusGuideSelectedThirdPaymentMethod;
            OperBusGridView.ViewBusGuideDateThirdPayment = model.ViewBusGuideDateThirdPayment;
            OperBusGridView.ViewBusNotes = model.ViewBusNotes;
            // init pageNum
            OperBusGridView.BusPageNumber = model.BusPageNumber;
            // init all filter selected data
            // Bus Group Code filter
            if (model.SelectedBusFilterGroupCode != null && !(model.IsRemoveBusGroupCodeFilter))
            {
                foreach (var filterGroupCode in model.SelectedBusFilterGroupCode)
                {
                    CheckBoxControlViewModel checkedItem = OperBusGridView.BusFilterGroupCode.Where(obj => obj.Id == filterGroupCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperBusGridView.BusFilterSelGroupCode.Add(checkedItem);
                    }
                }
                OperBusGridView.BusFilterGroupCode = OperBusGridView.BusFilterGroupCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Bus Group Name filter
            if (model.SelectedBusFilterGroupName != null && !(model.IsRemoveBusGroupNameFilter))
            {
                foreach (var filterGroupName in model.SelectedBusFilterGroupName)
                {
                    CheckBoxControlViewModel checkedItem = OperBusGridView.BusFilterGroupName.Where(obj => obj.Id == filterGroupName).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperBusGridView.BusFilterSelGroupName.Add(checkedItem);
                    }
                }
                OperBusGridView.BusFilterGroupName = OperBusGridView.BusFilterGroupName.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Bus Customer filter
            if (model.SelectedBusFilterCustomerCode != null && !(model.IsRemoveBusCustomerCodeFilter))
            {
                foreach (var filterCustomerCode in model.SelectedBusFilterCustomerCode)
                {
                    CheckBoxControlViewModel checkedItem = OperBusGridView.BusFilterCustomerCode.Where(obj => obj.Id == filterCustomerCode).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperBusGridView.BusFilterSelCustomerCode.Add(checkedItem);
                    }
                }
                OperBusGridView.BusFilterCustomerCode = OperBusGridView.BusFilterCustomerCode.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Bus Status filter
            if (model.SelectedBusFilterStatus != null && !(model.IsRemoveBusStatusFilter))
            {
                foreach (var filterStatus in model.SelectedBusFilterStatus)
                {
                    CheckBoxControlViewModel checkedItem = OperBusGridView.BusFilterStatus.Where(obj => obj.Id == filterStatus).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperBusGridView.BusFilterSelStatus.Add(checkedItem);
                    }
                }
                OperBusGridView.BusFilterStatus = OperBusGridView.BusFilterStatus.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Bus Vendor Name filter
            if (model.SelectedBusFilterVendorName != null && !(model.IsRemoveBusVendorNameFilter))
            {
                foreach (var filterVendorName in model.SelectedBusFilterVendorName)
                {
                    CheckBoxControlViewModel checkedItem = OperBusGridView.BusFilterVendorName.Where(obj => obj.Id == filterVendorName).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperBusGridView.BusFilterSelVendorName.Add(checkedItem);
                    }
                }
                OperBusGridView.BusFilterVendorName = OperBusGridView.BusFilterVendorName.OrderByDescending(grp => grp.IsSelected).ToList();
            }
            // Bus Start City filter
            if (model.SelectedBusFilterStartCity != null && !(model.IsRemoveBusStartCityFilter))
            {
                foreach (var filterStartCity in model.SelectedBusFilterStartCity)
                {
                    CheckBoxControlViewModel checkedItem = OperBusGridView.BusFilterStartCity.Where(obj => obj.Id == filterStartCity).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperBusGridView.BusFilterSelStartCity.Add(checkedItem);
                    }
                }
                OperBusGridView.BusFilterStartCity = OperBusGridView.BusFilterStartCity.OrderByDescending(scity => scity.IsSelected).ToList();
            }
            // Bus End City filter
            if (model.SelectedBusFilterEndCity != null && !(model.IsRemoveBusEndCityFilter))
            {
                foreach (var filterEndCity in model.SelectedBusFilterEndCity)
                {
                    CheckBoxControlViewModel checkedItem = OperBusGridView.BusFilterEndCity.Where(obj => obj.Id == filterEndCity).FirstOrDefault();
                    if (checkedItem != null)
                    {
                        checkedItem.IsSelected = true;
                        OperBusGridView.BusFilterSelEndCity.Add(checkedItem);
                    }
                }
                OperBusGridView.BusFilterEndCity = OperBusGridView.BusFilterEndCity.OrderByDescending(ecity => ecity.IsSelected).ToList();
            }
        }
        private void InitHotelGridViewData(OperationHotelGridBData HotelData, OperationHotelGridViewModel OperHotelGridView)
        {
            OperHotelGridView.Rows = new List<OperationHotelGridRowViewModel>();
            OperHotelGridView.GroupStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.VendorInfo = new List<OperationHotelVendorInfoViewModel>();
            OperHotelGridView.VendorStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.Currency = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.PaymentMethod = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.CommissionStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.SearchArrivalCity = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.SearchDepartureCity = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.SearchNationality = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.SearchStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            OperHotelGridView.Employee = new List<System.Web.WebPages.Html.SelectListItem>();
            // Pay method init
            if (HotelData != null && HotelData.PayMethod != null)
                foreach (var pay in HotelData.PayMethod)
                {
                    OperHotelGridView.PaymentMethod.Add(new System.Web.WebPages.Html.SelectListItem { Text = pay.Value, Value = pay.Key.ToString() });
                }
            // VendorInfo init
            if (HotelData != null && HotelData.VendorInfo != null)
                foreach (var vnd in HotelData.VendorInfo)
                {
                    OperHotelGridView.VendorInfo.Add(new OperationHotelVendorInfoViewModel
                    {
                        VendorID = vnd.VendorID,
                        VendorAddress = vnd.VendorAddress,
                        VendorName = vnd.VendorName,
                        VendorCity = vnd.VendorCity,
                        VendorContactPerson = vnd.VendorContactPerson,
                        VendorEmail = vnd.VendorEmail,
                        VendorPhone = vnd.VendorPhone,
                        VendorIsFind = vnd.IsFind == null ? false : Convert.ToBoolean(vnd.IsFind),
                    });
                }
            // Search Arrival, dep City 
            if (HotelData != null && HotelData.SearchCity != null)
                foreach (var city in HotelData.SearchCity)
                {
                    OperHotelGridView.SearchArrivalCity.Add(new System.Web.WebPages.Html.SelectListItem { Text = city.Value, Value = city.Value });
                    OperHotelGridView.SearchDepartureCity.Add(new System.Web.WebPages.Html.SelectListItem { Text = city.Value, Value = city.Value });
                }
            if (HotelData != null && HotelData.SearchNationality != null)
                foreach (var nationality in HotelData.SearchNationality)
                {
                    OperHotelGridView.SearchNationality.Add(new System.Web.WebPages.Html.SelectListItem { Text = nationality.Value, Value = nationality.Key.ToString() });
                }
            // employee init
            if (HotelData != null && HotelData.Employee != null)
                foreach (var emp in HotelData.Employee)
                {
                    OperHotelGridView.Employee.Add(new System.Web.WebPages.Html.SelectListItem { Text = emp.Value, Value = emp.Key.ToString() });
                }

            // Group status filter
            OperHotelGridView.HotelFilterGroupStatus = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelGroupStatus = new List<CheckBoxControlViewModel>();
            // status filter
            OperHotelGridView.HotelFilterStatus = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelStatus = new List<CheckBoxControlViewModel>();
            // Arrival city filter
            OperHotelGridView.HotelFilterArrivalCity = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelArrivalCity = new List<CheckBoxControlViewModel>();
            // Day of Arrival filter
            OperHotelGridView.HotelFilterDayofArrival= new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelDayofArrival = new List<CheckBoxControlViewModel>();
            // Month of Arrival filter
            OperHotelGridView.HotelFilterMonthofArrival = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelMonthofArrival = new List<CheckBoxControlViewModel>();
            // Estimated Number Rooms filter
            OperHotelGridView.HotelFilterEstNumberRoom = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelEstNumberRoom = new List<CheckBoxControlViewModel>();
            // Group Code filter
            OperHotelGridView.HotelFilterGroupCode = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelGroupCode = new List<CheckBoxControlViewModel>();
            // Group Name filter
            OperHotelGridView.HotelFilterGroupName = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelGroupName = new List<CheckBoxControlViewModel>();
            // Customer filter
            OperHotelGridView.HotelFilterCustomerCode = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelCustomerCode = new List<CheckBoxControlViewModel>();
            // Vendor Name filter
            OperHotelGridView.HotelFilterVendorName = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelVendorName = new List<CheckBoxControlViewModel>();
            // Vendor City filter
            OperHotelGridView.HotelFilterVendorCity = new List<CheckBoxControlViewModel>();
            OperHotelGridView.HotelFilterSelVendorCity = new List<CheckBoxControlViewModel>();
            // status vendor status, status filter init
            if (HotelData != null && HotelData.VendorStatus != null)
                foreach (var status in HotelData.VendorStatus)
                {
                    OperHotelGridView.VendorStatus.Add(new System.Web.WebPages.Html.SelectListItem() { Text = status.Value, Value = status.Key.ToString() });
                }
            // status init
            if (HotelData != null && HotelData.GroupStatus != null)
                foreach (var status in HotelData.GroupStatus)
                {
                    OperHotelGridView.GroupStatus.Add(new System.Web.WebPages.Html.SelectListItem() { Text = status.Value, Value = status.Key.ToString() });
                    OperHotelGridView.SearchStatus.Add(new System.Web.WebPages.Html.SelectListItem() { Text = status.Value, Value = status.Key.ToString() });
                }
            // status vendor status, status filter init
            if (HotelData != null && HotelData.FilterVendorStatus != null)
                foreach (var status in HotelData.FilterVendorStatus)
                {
                    OperHotelGridView.HotelFilterStatus.Add(new CheckBoxControlViewModel { Id = status.Key.ToString(), Name = status.Value });
                }
            //Filter status init 
            if (HotelData != null && HotelData.FilterGroupStatus != null)
                foreach (var status in HotelData.FilterGroupStatus)
                {
                    OperHotelGridView.HotelFilterGroupStatus.Add(new CheckBoxControlViewModel { Id = status.Key.ToString(), Name = status.Value });
                }
            // Day of Arrival filter init
            if (HotelData != null && HotelData.FilterDayofArrival != null)
                foreach (var dayofarr in HotelData.FilterDayofArrival)
                {
                    OperHotelGridView.HotelFilterDayofArrival.Add(new CheckBoxControlViewModel { Id = dayofarr.Key.ToString(), Name = dayofarr.Value });
                }
            // Month of Arrival filter init
            if (HotelData != null && HotelData.FilterMonthofArrival != null)
                foreach (var Monthofarr in HotelData.FilterMonthofArrival)
                {
                    OperHotelGridView.HotelFilterMonthofArrival.Add(new CheckBoxControlViewModel { Id = Monthofarr.Key.ToString(), Name = Monthofarr.Value });
                }
            // Arrival City filter init
            if (HotelData != null && HotelData.FilterArrivalCity != null)
                foreach (var arrcity in HotelData.FilterArrivalCity)
                {
                    OperHotelGridView.HotelFilterArrivalCity.Add(new CheckBoxControlViewModel { Id = arrcity, Name = arrcity });
                }
            // Estimated Number Rooms filter init
            if (HotelData != null && HotelData.FilterEstRoomNumber != null)
                foreach (var estRoom in HotelData.FilterEstRoomNumber)
                {
                    OperHotelGridView.HotelFilterEstNumberRoom.Add(new CheckBoxControlViewModel { Id = Convert.ToInt16(estRoom).ToString(), Name = Convert.ToInt16(estRoom).ToString() });
                }
            // Group Code filter init
            if (HotelData != null && HotelData.FilterGroupCode != null)
                foreach (var grp in HotelData.FilterGroupCode)
                {
                    OperHotelGridView.HotelFilterGroupCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Group Name filter init
            if (HotelData != null && HotelData.FilterGroupName != null)
                foreach (var grp in HotelData.FilterGroupName)
                {
                    OperHotelGridView.HotelFilterGroupName.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Customer filter init
            if (HotelData != null && HotelData.FilterCustomerCode != null)
                foreach (var cust in HotelData.FilterCustomerCode)
                {
                    OperHotelGridView.HotelFilterCustomerCode.Add(new CheckBoxControlViewModel { Id = cust.Key.ToString(), Name = cust.Value });
                }
            // Vendor Name filter init
            if (HotelData != null && HotelData.FilterVendorName != null)
                foreach (var vndname in HotelData.FilterVendorName)
                {
                    OperHotelGridView.HotelFilterVendorName.Add(new CheckBoxControlViewModel { Id = vndname.Key.ToString(), Name = vndname.Value });
                }
            // Vendor City filter init
            if (HotelData != null && HotelData.FilterVendorCity != null)
                foreach (var vndCity in HotelData.FilterVendorCity)
                {
                    OperHotelGridView.HotelFilterVendorCity.Add(new CheckBoxControlViewModel { Id = vndCity, Name = vndCity });
                }
            decimal OutstandingBalanceSum = 0;
            decimal ComAmtSum = 0;
            decimal ComReceivedAmtSum = 0;
            decimal TotalPaidSum = 0;
            decimal QuotaRoomDiffSum = 0;
            decimal OutsatndingComAmtSum = 0;
            decimal OutsatndingPaymentSum = 0;

            decimal CADOutstandingBalanceSum = 0;
            decimal CADComAmtSum = 0;
            decimal CADComReceivedAmtSum = 0;
            decimal CADTotalPaidSum = 0;
            decimal CADQuotaRoomDiffSum = 0;
            decimal CADOutsatndingComAmtSum = 0;
            decimal CADOutsatndingPaymentSum = 0;
            if (HotelData != null && HotelData.Rows != null)
                foreach (var htl in HotelData.Rows)
                {
                    string ContractPath = htl.VendorContractPath != null ? System.Configuration.ConfigurationManager.AppSettings["UploadVendorContract"] + htl.VendorContractPath : null;
                    string ContractGroupPath = htl.VendorGroupContractPath != null ? System.Configuration.ConfigurationManager.AppSettings["UploadVendorConfirmContract"] + htl.VendorGroupContractPath : null;
                    bool FileCompDaysCompleted = true;
                    if (HotelData.Rows.Any(row => row.GroupID == htl.GroupID && row.VendorSelStatus != "Made"))
                        FileCompDaysCompleted = false;
                    // string ArrHtmlDate = String.Format("'{0}'",(Convert.ToDateTime(htl.ArrivalDate)).ToString("dd/MM/yy"));
                
                    decimal HotelAmt = Convert.ToDecimal(htl.SglAmt) * htl.SglCount + Convert.ToDecimal(htl.DblAmt) * htl.DblCount + Convert.ToDecimal(htl.TwnAmt) * htl.TwnCount + Convert.ToDecimal(htl.TrpAmt) * htl.TrpCount + Convert.ToDecimal(htl.QudAmt) * htl.QudCount + Convert.ToDecimal(htl.GudAmt) * htl.GudCount;
                    decimal ComAmt = Convert.ToDecimal(htl.CommissionPerc) / 100 * (HotelAmt);
                    decimal TotalPaid = Convert.ToDecimal(htl.FirstPayAmt) + Convert.ToDecimal(htl.SecondPayAmt) + Convert.ToDecimal(htl.ThirdPayAmt);
                    decimal BreakDownTotal = Convert.ToDecimal(htl.AllSerAmt) - Convert.ToDecimal(htl.Less);
                    decimal TotalCost = BreakDownTotal + Convert.ToDecimal(htl.ExtraCost) - ComAmt;
                    decimal OutstandingBalance = BreakDownTotal - TotalPaid - Convert.ToDecimal(htl.Less);
                    decimal QuotaRoomDiff = Convert.ToDecimal(htl.QuotaRoom) - Convert.ToDecimal(htl.DblAmt);
                    int Nights = htl.CheckInDate != null && htl.CheckOutDate != null ? ((Convert.ToDateTime(htl.CheckOutDate) - Convert.ToDateTime(htl.CheckInDate)).Days) : 0;
                    int RoomCount = htl.SglCount + htl.DblCount + htl.TwnCount + htl.TrpCount + htl.QudCount + htl.DrvCount + htl.GudCount;
                    string QuotaCurr = htl.QuotaCurr == null ? "USD" : (htl.QuotaCurr == "US" || htl.QuotaCurr == "USD") ? "USD" : (htl.QuotaCurr == "CA" || htl.QuotaCurr == "CAD") ? "CAD" : "";

                    OperHotelGridView.Rows.Add(new OperationHotelGridRowViewModel
                    {
                        GroupID = htl.GroupID.ToString(),
                        GroupCode = htl.GroupCode,
                        CustomerCode = htl.Customer,
                        GroupName = htl.GroupName,
                        GroupBookedUnder = htl.GroupBookedUnder,
                        DateFileReceived = htl.GroupPushedDate != null ? Convert.ToDateTime(htl.GroupPushedDate).ToString("ddd, dd/MMM/yy") : "",
                        DateFileCompleted = htl.GroupPushedFileCompDate != null ? Convert.ToDateTime(htl.GroupPushedFileCompDate).ToString("ddd, dd/MMM/yy") : "",
                        FileCompDays = FileCompDaysCompleted ? (Convert.ToDateTime(htl.GroupPushedFileCompDate) - Convert.ToDateTime(htl.GroupPushedDate)).Days.ToString():"",
                        NoOfPerson = htl.NumOfPerson.ToString(),
                        EstNoOfPerson = htl.EstNumOfPerson.ToString(),
                        ArrivalDate = (Convert.ToDateTime(htl.ArrivalDate)).ToString("ddd, dd/MMM/yy"),
                        DayOfArrival = (Convert.ToDateTime(htl.ArrivalDate)).ToString("dddd"),
                        MonthOfArrival = (Convert.ToDateTime(htl.ArrivalDate)).ToString("MMMM"),
                        ArrivalCity = htl.ArrivalCity,
                        DepartureDate = (Convert.ToDateTime(htl.DepartureDate)).ToString("ddd, dd/MMM/yy"),
                        //DepartureCity = htl.DepartureCity,
                        SelectedGroupStatus = htl.GroupSelStatus,
                        SelectedVendorStatus = htl.VendorSelStatus,
                        RoomCount = RoomCount.ToString(),
                        VendorID = htl.VendorID,
                        SelectedEmployee = HotelData.Employee.Any(emp => emp.Key == htl.EmployeeID) ? HotelData.Employee.Where(emp => emp.Key == htl.EmployeeID).SingleOrDefault().Value : null,
                        VendorName = htl.VendorName,
                        VendorAddress = htl.VendorAddress,
                        VendorContactName = htl.VendorContactName,
                        VendorCity = htl.VendorCity,
                        VendorPhone = htl.VendorPhone,
                        VendorEmail = htl.VendorEmail,
                        VendorNote = htl.Note,
                        TaxPrc = htl.Tax != null? Convert.ToDouble(htl.Tax).ToString("F"):"0",
                        OccTax = htl.OccTax != null ? Convert.ToDecimal(htl.OccTax).ToString("F") : "0",
                        Comp = htl.Comp != null ? Convert.ToInt16(htl.Comp).ToString() : "0",
                        Bag = htl.Luggage != null ? Convert.ToDecimal(htl.Luggage).ToString("F") : "0",
                        ABF = htl.ABF != null ? Convert.ToDecimal(htl.ABF).ToString("F") : "0",
                        CBF = htl.CBF != null ? Convert.ToDecimal(htl.CBF).ToString("F") : "0",
                        Lunch = htl.Lunch != null ? Convert.ToDecimal(htl.Lunch).ToString("F") : "0",
                        Dinner = htl.Dinner != null ? Convert.ToDecimal(htl.Dinner).ToString("F") : "0",
                        BagChecked = htl.LuggageChecked != null ? Convert.ToBoolean(htl.LuggageChecked) : false,
                        ABFChecked = htl.ABFChecked != null ? Convert.ToBoolean(htl.ABFChecked) : false,
                        CBFChecked = htl.CBFChecked != null ? Convert.ToBoolean(htl.CBFChecked) : false,
                        LunchChecked = htl.LunchChecked != null ? Convert.ToBoolean(htl.LunchChecked) : false,
                        DinnerChecked = htl.DinnerChecked != null ? Convert.ToBoolean(htl.DinnerChecked) : false,
                        CheckInDate = htl.CheckInDate.ToString("ddd, dd/MMM/yy"),
                        CheckOutDate = htl.CheckOutDate != null? Convert.ToDateTime(htl.CheckOutDate).ToString("ddd, dd/MMM/yy"):"",
                        EstimatedNumberRooms = htl.EstNumRooms != null ? Convert.ToInt16(htl.EstNumRooms).ToString():"0",
                        QuotaRoom = htl.QuotaRoom != null?Convert.ToDecimal(htl.QuotaRoom).ToString("F"):"0",
                        QuotaRoomDiff = QuotaRoomDiff.ToString("F"),
                        QuotaTax = htl.QuotaTax != null ? Convert.ToDouble(htl.QuotaTax).ToString("F") : "0",
                        QuotaOccTax = htl.QuotaOccTax != null ? Convert.ToDecimal(htl.QuotaOccTax).ToString("F") : "0",
                        QuotaBrk = htl.QuotaBrk != null ? Convert.ToDecimal(htl.QuotaBrk).ToString("F") : "0",
                        QuotaLg = htl.QuotaLg != null ? Convert.ToDecimal(htl.QuotaLg).ToString("F") : "0",
                        QuotaNight = htl.QuotaNight != null ? Convert.ToInt16(htl.QuotaLg).ToString() : "",
                        QuotaVendorName = htl.QuotaVendorName,
                        CommissionPrc = htl.CommissionPerc != null ? Convert.ToDecimal(htl.CommissionPerc).ToString("F") : "0",
                        SelectedCommissionStatus = htl.CommissionStatus,
                        ComAmount = ComAmt.ToString("F"),
                        ComDifference = (Convert.ToDecimal(htl.CommissionRecAmt) - ComAmt).ToString("F"),
                        CommissionReceived = htl.CommissionRecAmt != null ? Convert.ToDecimal(htl.CommissionRecAmt).ToString("F") : "0",
                        CommissionDateReceived = htl.CommissionRecDate != null ? Convert.ToDateTime(htl.CommissionRecDate).ToString("ddd, dd/MMM/yy") : "",
                        CheckNumber = htl.CommissionCheckNum,
                        CheckAmount = htl.CommissionCheckAmt != null ? Convert.ToDecimal(htl.CommissionCheckAmt).ToString("F") : "0",
                        AccountingMemo = htl.AccountingMemo,
                        ClientBookingCode = htl.ClientBookingCode,
                        ExtraCost = htl.ExtraCost != null ? Convert.ToDecimal(htl.ExtraCost).ToString("F") : "0",
                        RefundReceivedHotel = htl.RefFromHotel != null ? Convert.ToDecimal(htl.RefFromHotel).ToString("F") : "0",
                        TotalInvoice = htl.TotalHotelInv != null ? Convert.ToDecimal(htl.TotalHotelInv).ToString("F") : "0",
                        TotalCharged = htl.TotalCharged != null ? Convert.ToDecimal(htl.TotalCharged).ToString("F") : "0",
                        SGLAmount = htl.SglAmt != null ? Convert.ToDecimal(htl.SglAmt).ToString("F") : "0",
                        DBLAmount = htl.DblAmt != null ? Convert.ToDecimal(htl.DblAmt).ToString("F") : "0",
                        TWNAmount = htl.TwnAmt != null ? Convert.ToDecimal(htl.TwnAmt).ToString("F") : "0",
                        TRPLAmount = htl.TrpAmt != null ? Convert.ToDecimal(htl.TrpAmt).ToString("F") : "0",
                        QUDAmount = htl.QudAmt != null ? Convert.ToDecimal(htl.QudAmt).ToString("F") : "0",
                        GuideAmount = htl.GudAmt != null ? Convert.ToDecimal(htl.GudAmt).ToString("F") : "0",
                        DriverAmount = htl.DrvAmt != null ? Convert.ToDecimal(htl.DrvAmt).ToString("F") : "0",
                        SelectedCurrency = QuotaCurr,
                        QuotaNote = htl.QuotaNote,
                        SGLCount = htl.SglCount.ToString(),
                        DBLCount = htl.DblCount.ToString(),
                        TWNCount = htl.TwnCount.ToString(),
                        TRPLCount = htl.TrpCount.ToString(),
                        QUDCount = htl.QudCount.ToString(),
                        DriverCount = htl.DrvCount.ToString(),
                        GuideCount = htl.GudCount.ToString(),
                        Nights = htl.CheckInDate != null && htl.CheckOutDate != null? ((Convert.ToDateTime(htl.CheckOutDate)-Convert.ToDateTime(htl.CheckInDate)).Days).ToString():"",
                        DateFirstPayment = htl.FirstPayDate != null ? Convert.ToDateTime(htl.FirstPayDate).ToString("dd/MMM/yyyy") : "",
                        FirstPaymentMethod = htl.FirstPayMethod,
                        FirstPayment = htl.FirstPayAmt != null ? Convert.ToDecimal(htl.FirstPayAmt).ToString("F") : "0",
                        DateSecondPayment = htl.SecondPayDate != null ? Convert.ToDateTime(htl.SecondPayDate).ToString("dd/MMM/yyyy") : "",
                        SecondPaymentMethod = htl.SecondPayMethod,
                        SecondPayment = htl.SecondPayAmt != null ? Convert.ToDecimal(htl.SecondPayAmt).ToString("F") : "0",
                        DateThirdPayment = htl.ThirdPayDate != null ? Convert.ToDateTime(htl.ThirdPayDate).ToString("dd/MMM/yyyy") : "",
                        ThirdPaymentMethod = htl.ThirdPayMethod,
                        ThirdPayment = htl.ThirdPayAmt != null ? Convert.ToDecimal(htl.ThirdPayAmt).ToString("F") : "0",
                        TotalPaid = TotalPaid.ToString("F"),
                        BreakDownTotal = BreakDownTotal.ToString("F"),
                        TotalCost = TotalCost.ToString("F"),
                        OutstandingBalance = OutstandingBalance.ToString("F"),
                        AuthDiff = (TotalPaid - Convert.ToDecimal(htl.TotalCharged)).ToString("F"),
                        VConfHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='OperGroupVendorConf(" + htl.GroupID + "," + htl.VendorID + "," + "\"" + Convert.ToDateTime(htl.ArrivalDate).ToString() + "\"" + ")'>Details</button></div>",
                        PayMeth1FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAmexVendorDetails(" + htl.GroupID + "," + htl.VendorID + "," + 1 + "," + "\"" + Convert.ToDateTime(htl.ArrivalDate).ToString() + "\"" + "," + "\"" + "Hotel" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                        PayMeth2FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAmexVendorDetails(" + htl.GroupID + "," + htl.VendorID + "," + 2 + "," + "\"" + Convert.ToDateTime(htl.ArrivalDate).ToString() + "\"" + "," + "\"" + "Hotel" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                        PayMeth3FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAmexVendorDetails(" + htl.GroupID + "," + htl.VendorID + "," + 3 + "," + "\"" + Convert.ToDateTime(htl.ArrivalDate).ToString() + "\"" + "," + "\"" + "Hotel" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                        VendorContractHtml = "<div style='text-align:center;'><button class='btn14 btn120 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationVendorContractDetails(" + "\"" + ContractPath + "\"" + ")'>General Contract</button></div>",
                        VendorGroupContractHtml = "<div style='text-align:center;'><button class='btn14 btn120 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationVendorContractDetails(" + "\"" + ContractGroupPath + "\"" + ")'>Vendor Contract</button></div>",
                    });
                    if (QuotaCurr == "CAD")
                    {
                        CADOutstandingBalanceSum = CADOutstandingBalanceSum + OutstandingBalance;
                        CADComAmtSum = CADComAmtSum + ComAmt;
                        CADComReceivedAmtSum = CADComReceivedAmtSum + Convert.ToDecimal(htl.CommissionRecAmt);
                        CADTotalPaidSum = CADTotalPaidSum + TotalPaid;
                        CADQuotaRoomDiffSum = CADQuotaRoomDiffSum + (QuotaRoomDiff * Nights) * (RoomCount > 0 ? RoomCount : (int)htl.EstNumRooms);
                        CADOutsatndingComAmtSum = CADOutsatndingComAmtSum + (ComAmt - Convert.ToDecimal(htl.CommissionRecAmt));
                        CADOutsatndingPaymentSum = CADOutsatndingPaymentSum + (OutstandingBalance - TotalPaid);
                    }
                    else if (QuotaCurr == "USD")
                    {
                        OutstandingBalanceSum = OutstandingBalanceSum + OutstandingBalance;
                        ComAmtSum = ComAmtSum + ComAmt;
                        ComReceivedAmtSum = ComReceivedAmtSum + Convert.ToDecimal(htl.CommissionRecAmt);
                        TotalPaidSum = TotalPaidSum + TotalPaid;
                        QuotaRoomDiffSum = QuotaRoomDiffSum + (QuotaRoomDiff * Nights) * (RoomCount > 0 ? RoomCount : (int)htl.EstNumRooms);
                        OutsatndingComAmtSum = OutsatndingComAmtSum + (ComAmt - Convert.ToDecimal(htl.CommissionRecAmt));
                        OutsatndingPaymentSum = OutsatndingPaymentSum + (OutstandingBalance - TotalPaid);
                    }               
                }
            // Calc Group Profit
            if (HotelData.SearchGroupCode != null)
            {
                OperHotelGridView.TotInv = Convert.ToDecimal(HotelData.TotInv);
                OperHotelGridView.TotInvCad = Convert.ToDecimal(HotelData.TotInvCad);
                OperHotelGridView.TotCost = OutstandingBalanceSum;
                OperHotelGridView.TotCostCad = CADOutstandingBalanceSum;
                OperHotelGridView.GroupProfit = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='HotelGroupProfit'></span><span class='OperationSumCAD GrpProfit' id='HotelGroupProfitCad'></span></label>";
                OperHotelGridView.TotInvoice = "<label class='form-control'>" + (HotelData.TotInv < 0 ? "<span class='OperationSumUSD SumControls10Size GrpProfit'>" : "<span class='OperationSumUSD SumControls10Sizeblack GrpProfit'>") + Convert.ToDecimal(HotelData.TotInv).ToString("F") + " USD" + (HotelData.TotInvCad == 0 ? "" : ",") + "</span>" + (HotelData.TotInvCad == 0 ? "" : (HotelData.TotInvCad < 0 ? "<span class='OperationSumCAD SumControls10Size GrpProfit'>" : "<span class='OperationSumCAD SumControls10Sizeblack GrpProfit'>") + Convert.ToDecimal(HotelData.TotInvCad).ToString("F") + " CAD" + "</span>") + "</label>";
                OperHotelGridView.ProfitPers = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='HotelProfitPers'></span><span class='OperationSumCAD GrpProfit' id='HotelProfitPersCAD'></span></label>"; 
            }
            OperHotelGridView.OutstandingBalanceSum = "<label class='form-control'>" + (OutstandingBalanceSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + OutstandingBalanceSum.ToString("F") + " USD" + (CADOutstandingBalanceSum == 0 ? "" : ",") + "</span>" + (CADOutstandingBalanceSum == 0 ? "" : (CADOutstandingBalanceSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADOutstandingBalanceSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperHotelGridView.ComAmtSum = "<label class='form-control'>" + (ComAmtSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + ComAmtSum.ToString("F") + " USD" + (CADComAmtSum == 0 ? "" : ",") + "</span>" + (CADComAmtSum == 0 ? "" : (CADComAmtSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADComAmtSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperHotelGridView.ComReceivedAmtSum = "<label class='form-control'>" + (ComReceivedAmtSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + ComReceivedAmtSum.ToString("F") + " USD" + (CADComReceivedAmtSum == 0 ? "" : ",") + "</span>" + (CADComReceivedAmtSum == 0 ? "" : (CADComReceivedAmtSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADComReceivedAmtSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperHotelGridView.TotalPaidSum = "<label class='form-control'>" + (TotalPaidSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + TotalPaidSum.ToString("F") + " USD" + (CADTotalPaidSum == 0 ? "" : ",") + "</span>" + (CADTotalPaidSum == 0 ? "" : (CADTotalPaidSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADTotalPaidSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperHotelGridView.QuotaRoomDiffSum = "<label class='form-control'>" + (QuotaRoomDiffSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + QuotaRoomDiffSum.ToString("F") + " USD" + (CADQuotaRoomDiffSum == 0 ? "" : ",") + "</span>" + (CADQuotaRoomDiffSum == 0 ? "" : (CADQuotaRoomDiffSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADQuotaRoomDiffSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperHotelGridView.OutsatndingComAmtSum = "<label class='form-control'>" + (OutsatndingComAmtSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + OutsatndingComAmtSum.ToString("F") + " USD" + (CADOutsatndingComAmtSum == 0 ? "" : ",") + "</span>" + (CADOutsatndingComAmtSum == 0 ? "" : (CADOutsatndingComAmtSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADOutsatndingComAmtSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperHotelGridView.OutsatndingPaymentSum = "<label class='form-control'>" + (OutsatndingPaymentSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + OutsatndingPaymentSum.ToString("F") + " USD" + (CADOutsatndingPaymentSum == 0 ? "" : ",") + "</span>" + (CADOutsatndingPaymentSum == 0 ? "" : (CADOutsatndingPaymentSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADOutsatndingPaymentSum.ToString("F") + " CAD" + "</span>") + "</label>";    
        }
        private void InitRoomGridViewData(OperationRoomGridBData RoomData, OperationRoomGridViewModel OperRoomGridView)
        {
            OperRoomGridView.Rows = new List<OperationRoomGridRowViewModel>();
            OperRoomGridView.GirRows = new List<OperationRoomGridGirRowViewModel>();
            OperRoomGridView.RoomType = new List<System.Web.WebPages.Html.SelectListItem>();
            OperRoomGridView.RoomTitles = new List<System.Web.WebPages.Html.SelectListItem>();
            OperRoomGridView.RoomTitleSingle = new List<System.Web.WebPages.Html.SelectListItem>();
            OperRoomGridView.RoomTitleDouble = new List<System.Web.WebPages.Html.SelectListItem>();
            OperRoomGridView.RoomTitleTwin = new List<System.Web.WebPages.Html.SelectListItem>();
            OperRoomGridView.RoomTitleTriple = new List<System.Web.WebPages.Html.SelectListItem>();
            OperRoomGridView.RoomTitleQuad = new List<System.Web.WebPages.Html.SelectListItem>();
            OperRoomGridView.RoomTitleDriver = new List<System.Web.WebPages.Html.SelectListItem>();
            OperRoomGridView.RoomTitleGuide = new List<System.Web.WebPages.Html.SelectListItem>();
           // OperRoomGridView.Titles = new List<OperTitleInfoViewModel>();
            // customer filter
            OperRoomGridView.RoomFilterCustomer = new List<CheckBoxControlViewModel>();
            OperRoomGridView.RoomFilterSelCustomer = new List<CheckBoxControlViewModel>();
            // Room Type filter
            OperRoomGridView.RoomFilterRoomType = new List<CheckBoxControlViewModel>();
            OperRoomGridView.RoomFilterSelRoomType = new List<CheckBoxControlViewModel>();
            // Room Title filter
            OperRoomGridView.RoomFilterRoomTitle = new List<CheckBoxControlViewModel>();
            OperRoomGridView.RoomFilterSelRoomTitle = new List<CheckBoxControlViewModel>();
            // Room type init, filter room type init
            if (RoomData != null && RoomData.Roomtype != null)
                foreach (var type in RoomData.Roomtype)
                {
                    OperRoomGridView.RoomType.Add(new System.Web.WebPages.Html.SelectListItem() { Text = type.Value, Value = type.Key.ToString() });
                    OperRoomGridView.RoomFilterRoomType.Add(new CheckBoxControlViewModel { Id = type.Key.ToString(), Name = type.Value });
                    switch (type.Value)
                    {
                        case "Single":
                            OperRoomGridView.RoomTitleSingle = RoomData.Title.Where(ttl => ttl.ServiceCode == "Single").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                            break;
                        case "Double":
                            OperRoomGridView.RoomTitleDouble = RoomData.Title.Where(ttl => ttl.ServiceCode == "Double").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                            break;
                        case "Twin":
                            OperRoomGridView.RoomTitleTwin = RoomData.Title.Where(ttl => ttl.ServiceCode == "Twin").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                            break;
                        case "Triple":
                            OperRoomGridView.RoomTitleTriple = RoomData.Title.Where(ttl => ttl.ServiceCode == "Triple").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                            break;
                        case "Quad":
                            OperRoomGridView.RoomTitleQuad = RoomData.Title.Where(ttl => ttl.ServiceCode == "Quad").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                            break;
                        case "Driver":
                            OperRoomGridView.RoomTitleDriver = RoomData.Title.Where(ttl => ttl.ServiceCode == "Driver").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                            break;
                        case "Guide":
                            OperRoomGridView.RoomTitleGuide = RoomData.Title.Where(ttl => ttl.ServiceCode == "Guide").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                            break;
                    }
                }
            // Room title init, filter room title init
            if (RoomData != null && RoomData.Title != null)
                foreach (var title in RoomData.Title)
                {
                    OperRoomGridView.RoomFilterRoomTitle.Add(new CheckBoxControlViewModel { Id = title.Title, Name = title.Title });
                    OperRoomGridView.RoomTitles.Add(new System.Web.WebPages.Html.SelectListItem() { Text = title.Title, Value = title.ServiceCode });
                }
            // Customer filter init
            if (RoomData != null && RoomData.Customer != null)
                foreach (var cust in RoomData.Customer)
                {
                    OperRoomGridView.RoomFilterCustomer.Add(new CheckBoxControlViewModel { Id = cust.Key.ToString(), Name = cust.Value });
                }
            int Room = 0;
            int Pax = 0;
            if (RoomData != null && RoomData.Rows != null)
                foreach (var room in RoomData.Rows)
                {
                    Room++;
                    Pax += room.NumOfPerson;
                    OperRoomGridView.Rows.Add(new OperationRoomGridRowViewModel
                    {
                        RoomGroupID = room.GroupID,
                        RoomLineNo = room.LineNo,
                        RoomGroupName = room.GroupName,
                        RoomGroupCode = room.GroupCode,
                        RoomCustomer = room.Customer,
                        RoomNoOfPerson = room.NumOfPerson.ToString(),
                        RoomSelectedRoomType = room.ServiceID.ToString(),
                        RoomType = RoomData.Roomtype.Where(rm=> rm.Key == room.ServiceID).SingleOrDefault().Value,
                        RoomDelete = "<div style='text-align:center;'><button class='btn14 btn-danger btn50 btnheight22' type='button' style='padding:0px;' onclick='RemoveRoomByLine(" + room.GroupID + "," + room.LineNo + ")'>Delete</button></div>",
                        RoomNumOfPersonRoom = room.NumOfPersonRoom.ToString(),
                        RoomSelectedRoomTitle = room.Title,
                        RoomNames = room.Names,
                        RoomNotes = room.Notes,
                        RoomCustomerId = room.CustomerID,
                        RoomFullBoard = room.FullBoard == null ? "No" : Convert.ToBoolean(room.FullBoard) == true ? "Yes" : "No",
                        RoomFullBoardCount = room.FullBoardCount.ToString(),
                    });
                }
            var RoomsByType = OperRoomGridView.Rows.GroupBy(row => row.RoomType).Select(row => new { Roomtype = row.Key, RoomCount = row.Count() }).ToList();
            OperRoomGridView.TotalSgl = RoomsByType.Any(room => room.Roomtype == "Single") ? RoomsByType.Where(room => room.Roomtype == "Single").SingleOrDefault().RoomCount.ToString() : "0";
            OperRoomGridView.TotalDbl = RoomsByType.Any(room => room.Roomtype == "Double") ? RoomsByType.Where(room => room.Roomtype == "Double").SingleOrDefault().RoomCount.ToString() : "0";
            OperRoomGridView.TotalTwn = RoomsByType.Any(room => room.Roomtype == "Twin") ? RoomsByType.Where(room => room.Roomtype == "Twin").SingleOrDefault().RoomCount.ToString() : "0";
            OperRoomGridView.TotalTrpl = RoomsByType.Any(room => room.Roomtype == "Triple") ? RoomsByType.Where(room => room.Roomtype == "Triple").SingleOrDefault().RoomCount.ToString() : "0";
            OperRoomGridView.TotalQud = RoomsByType.Any(room => room.Roomtype == "Quad") ? RoomsByType.Where(room => room.Roomtype == "Quad").SingleOrDefault().RoomCount.ToString() : "0";
            OperRoomGridView.TotalDriver = RoomsByType.Any(room => room.Roomtype == "Driver") ? RoomsByType.Where(room => room.Roomtype == "Driver").SingleOrDefault().RoomCount.ToString() : "0";
            OperRoomGridView.TotalGuide = RoomsByType.Any(room => room.Roomtype == "Guide") ? RoomsByType.Where(room => room.Roomtype == "Guide").SingleOrDefault().RoomCount.ToString() : "0";

            if (RoomData != null && RoomData.GirRows != null)
                foreach (var GirFb in RoomData.GirRows)
                    OperRoomGridView.GirRows.Add(new OperationRoomGridGirRowViewModel
                    {
                        GirFullBoardCustomerID = GirFb.CustomerID,
                        GirCustomerName = GirFb.CustomerName,
                        GirFullBoardCount = GirFb.FullBoardCount.ToString(),
                        GirSSupCount = GirFb.SSupCount.ToString(),
                        GirPax = GirFb.Pax.ToString(),
                        GirFullBoardGroupID = GirFb.GroupID,
                        GirPerPrice = GirFb.PerPrice != null ? Convert.ToDecimal(GirFb.PerPrice).ToString("F") : "",
                        GirFullBoardPrice = GirFb.FullBoardPrice != null ? Convert.ToDecimal(GirFb.FullBoardPrice).ToString("F") : "",
                        GirSingleSupPrice = GirFb.SingleSupPrice != null ? Convert.ToDecimal(GirFb.SingleSupPrice).ToString("F") : "",
                        GirPerPriceCad = GirFb.PerPriceCad != null ? Convert.ToDecimal(GirFb.PerPriceCad).ToString("F") : "",
                        GirFullBoardPriceCad = GirFb.FullBoardPriceCad != null ? Convert.ToDecimal(GirFb.FullBoardPriceCad).ToString("F") : "",
                        GirSingleSupPriceCad = GirFb.SingleSupPriceCad != null ? Convert.ToDecimal(GirFb.SingleSupPriceCad).ToString("F") : "",
                    });
            OperRoomGridView.TotalRooms = Room.ToString();
            OperRoomGridView.TotalPax = Pax.ToString();
            OperRoomGridView.IsGir = RoomData.IsGir;
            OperRoomGridView.RoomGroupQuotaID = RoomData.QuotaID != null ? RoomData.QuotaID.ToString():null;
        }
        private void InitAttractionsGridViewData(OperationAttractionsGridBData AttractionsData, OperationAttractionsGridViewModel OperAttractionsGridView)
        {
            OperAttractionsGridView.Rows = new List<OperationAttractionsGridRowViewModel>();
            OperAttractionsGridView.VendorInfo = new List<OperationAttractionsVendorInfoViewModel>();
            OperAttractionsGridView.VendorStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            OperAttractionsGridView.RestService = new List<System.Web.WebPages.Html.SelectListItem>();
            OperAttractionsGridView.PaymentMethod = new List<System.Web.WebPages.Html.SelectListItem>();
            OperAttractionsGridView.Employee = new List<System.Web.WebPages.Html.SelectListItem>();
            // Pay method init
            if (AttractionsData != null && AttractionsData.PayMethod != null)
                foreach (var pay in AttractionsData.PayMethod)
                {
                    OperAttractionsGridView.PaymentMethod.Add(new System.Web.WebPages.Html.SelectListItem { Text = pay.Value, Value = pay.Key.ToString() });
                }
            // VendorInfo init
            if (AttractionsData != null && AttractionsData.VendorInfo != null)
                foreach (var vnd in AttractionsData.VendorInfo)
                {
                    OperAttractionsGridView.VendorInfo.Add(new OperationAttractionsVendorInfoViewModel
                    {
                        VendorID = vnd.VendorID,
                        VendorAddress = vnd.VendorAddress,
                        VendorName = vnd.VendorName,
                        VendorCity = vnd.VendorCity,
                        VendorContactPerson = vnd.VendorContactPerson,
                        VendorEmail = vnd.VendorEmail,
                        VendorPhone = vnd.VendorPhone,
                        VendorType = vnd.VendorType,
                        VendorIsFind = vnd.IsFind == null ? false : Convert.ToBoolean(vnd.IsFind),
                    });
                }
            if (AttractionsData != null && AttractionsData.VendorStatus != null)
                foreach (var status in AttractionsData.VendorStatus)
                {
                    OperAttractionsGridView.VendorStatus.Add(new System.Web.WebPages.Html.SelectListItem() { Text = status.Value, Value = status.Key.ToString() });
                }
            if (AttractionsData != null && AttractionsData.RestServices != null)
                foreach (var service in AttractionsData.RestServices)
                {
                    OperAttractionsGridView.RestService.Add(new System.Web.WebPages.Html.SelectListItem() { Text = service.Value, Value = service.Key.ToString() });
                }
            // employee init
            if (AttractionsData != null && AttractionsData.Employee != null)
                foreach (var emp in AttractionsData.Employee)
                {
                    OperAttractionsGridView.Employee.Add(new System.Web.WebPages.Html.SelectListItem { Text = emp.Value, Value = emp.Key.ToString() });
                }
            decimal TotalPaidSum = 0;
            decimal DifferenceSum = 0;
            decimal OutstandingAmtSum = 0;
            decimal TotalDiffPaidChargedSum = 0;
            decimal TotalCostSum = 0;
            decimal CADTotalPaidSum = 0;
            decimal CADDifferenceSum = 0;
            decimal CADOutstandingAmtSum = 0;
            decimal CADTotalDiffPaidChargedSum = 0;
            decimal CADTotalCostSum = 0;
            if (AttractionsData != null && AttractionsData.Rows != null)
                foreach (var Attr in AttractionsData.Rows)
                {
                    string ContractGroupPath = Attr.AttractionsGroupContractPath != null ? System.Configuration.ConfigurationManager.AppSettings["UploadVendorConfirmContract"] + Attr.AttractionsGroupContractPath : null;
                    decimal TotalPaid = Convert.ToDecimal(Attr.FirstPayAmt) + Convert.ToDecimal(Attr.SecondPayAmt) + Convert.ToDecimal(Attr.ThirdPayAmt);
                    decimal DifferenceTotalPaid_TotalCharged = TotalPaid - Convert.ToDecimal(Attr.CCChargeAmt);
                    decimal Difference = Convert.ToDecimal(Attr.QuotaRate) - Convert.ToDecimal(Attr.UnitRate);
                    decimal OutstandingAmt = TotalPaid - Convert.ToDecimal(Attr.UnitRate) * Convert.ToInt32(Attr.NumOfPerson);
                    decimal TotalCost = Convert.ToDecimal(Attr.UnitRate) * Convert.ToInt32(Attr.NumOfPerson);
                    string QuotaCurrency = Attr.QuotaCurrency == null ? "USD" : (Attr.QuotaCurrency == "US" || Attr.QuotaCurrency == "USD") ? "USD" : (Attr.QuotaCurrency == "CA" || Attr.QuotaCurrency == "CAD") ? "CAD" : "";
                
                    OperAttractionsGridView.Rows.Add(new OperationAttractionsGridRowViewModel()
                    {
                        AttractionsGroupID = Attr.GroupID.ToString(),
                        AttractionsVendorID = Attr.VendorID,
                        AttractionsGroupCode = Attr.GroupCode,
                        AttractionsGroupName = Attr.GroupName,
                        AttractionsUnitRate = Attr.UnitRate != null ? Convert.ToDecimal(Attr.UnitRate).ToString("F") : "0",
                        AttractionsDeposit = Attr.Deposit != null ? Convert.ToDecimal(Attr.Deposit).ToString("F") : "0",
                        AttractionsDepositDate = Attr.DepositDate != null ? Convert.ToDateTime(Attr.DepositDate).ToString("ddd, dd/MMM/yy") : "",
                        AttractionsTotalAmountPaid = TotalPaid.ToString("F"),
                        AttractionsDifferenceTotalPaid_TotalCharged = DifferenceTotalPaid_TotalCharged.ToString("F"),
                        AttractionsDifference = Difference.ToString("F"),
                        AttractionsOutstandingAmt = OutstandingAmt.ToString("F"),
                        AttractionsTotalCost = TotalCost.ToString("F"),
                        AttractionsDepositAmountPaid = Attr.DepositAmtPaid != null ? Convert.ToDecimal(Attr.DepositAmtPaid).ToString("F") : "0",
                        AttractionsCreditCardChargeAmount = Attr.CCChargeAmt != null ? Convert.ToDecimal(Attr.CCChargeAmt).ToString("F") : "0",
                        AttractionsSelectedEmployee = AttractionsData.Employee.Any(emp => emp.Key == Attr.EmployeeID) ? AttractionsData.Employee.Where(emp => emp.Key == Attr.EmployeeID).SingleOrDefault().Value : null,
                        AttractionsPax = Attr.NumOfPerson.ToString(),
                        AttractionsEstNoOfPerson = Attr.EstNumOfPerson.ToString(),
                        AttractionsCustomer = Attr.Customer,
                        AttractionsCreditCardMemo = Attr.CCMemo,
                        AttractionsCity = Attr.VendorCity,
                        AttractionsAddress = Attr.VendorAddress,
                        AttractionsEmail = Attr.VendorEmail,
                        AttractionsPhone = Attr.VendorPhone,
                        AttractionsSupplier = Attr.VendorName,
                        AttractionsCategory = Attr.Category,
                        AttractionsIsGuideInvoice = Attr.IsGuideInvoice != null ? Convert.ToBoolean(Attr.IsGuideInvoice) : false,
                        AttractionsGuideInvoicePrice = Attr.GuideInvoicePrice != null ? Convert.ToDecimal(Attr.GuideInvoicePrice).ToString("F") : "0",
                        AttractionsIsInvoice = Attr.IsInvoice != null ? Convert.ToBoolean(Attr.IsInvoice) : false,
                        AttractionsInvoicePrice = Attr.InvoicePrice != null ? Convert.ToDecimal(Attr.InvoicePrice).ToString("F") : "0",
                        AttractionsSelectedVendorStatus = Attr.VendorSelStatus,
                        AttractionsSelectedRestService = Attr.RestSelService,
                        AttractionsType = Attr.Type,
                        AttractionsOldRestCategory = Attr.Type,
                        AttractionsDate = (Convert.ToDateTime(Attr.StartDate)).ToString("ddd, dd/MMM/yy"),
                        AttractionsTime = Attr.Time != null ? Convert.ToDateTime(Attr.Time).ToString("HH:mm") : "",
                        AttractionsDone = Attr.Done != null ? Convert.ToDateTime(Attr.Done).ToString("ddd, dd/MMM/yy") : "",
                        AttractionsContact = Attr.VendorContactName,
                        AttractionsDateFirstPayment = Attr.FirstPayDate != null ? Convert.ToDateTime(Attr.FirstPayDate).ToString("dd/MMM/yyyy") : "",
                        AttractionsSelectedFirstPaymentMethod = Attr.FirstPayMethod,
                        AttractionsFirstPayment = Attr.FirstPayAmt != null ? Convert.ToDecimal(Attr.FirstPayAmt).ToString("F") : "0",
                        AttractionsDateSecondPayment = Attr.SecondPayDate != null ? Convert.ToDateTime(Attr.SecondPayDate).ToString("dd/MMM/yyyy") : "",
                        AttractionsSelectedSecondPaymentMethod = Attr.SecondPayMethod,
                        AttractionsSecondPayment = Attr.SecondPayAmt != null ? Convert.ToDecimal(Attr.SecondPayAmt).ToString("F") : "0",
                        AttractionsDateThirdPayment = Attr.ThirdPayDate != null ? Convert.ToDateTime(Attr.ThirdPayDate).ToString("dd/MMM/yyyy") : "",
                        AttractionsSelectedThirdPaymentMethod = Attr.ThirdPayMethod,
                        AttractionsThirdPayment = Attr.ThirdPayAmt != null ? Convert.ToDecimal(Attr.ThirdPayAmt).ToString("F") : "0",
                        AttractionsGroupContractHtml = "<div style='text-align:center;'><button class='btn14 btn120 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationVendorContractDetails(" + "\"" + ContractGroupPath + "\"" + ")'>Vendor Contract</button></div>",
                        AttractionsConfHtml = Attr.Type == null ? "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='OperGroupAttractionsConfLoad(" + Attr.GroupID + "," + Attr.VendorID + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + "Attractions" + "\"" + ")'>Details</button></div>"
                                                                : "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='OperGroupAttractionsConfLoad(" + Attr.GroupID + "," + Attr.VendorID + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + "Restaurants" + "\"" + ")'>Details</button></div>",
                        AttractionsPayMeth1FormHtml = Attr.Type == null ? "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAttractionsAmexVendorDetails(" + Attr.GroupID + "," + Attr.VendorID + "," + 1 + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + "Attractions" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>"
                                                                               : "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAttractionsAmexVendorDetails(" + Attr.GroupID + "," + Attr.VendorID + "," + 1 + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + "Restaurants" + "\"" + "," + "\"" + Attr.Type + "\"" + ")'>Detail</button></div>",
                        AttractionsPayMeth2FormHtml = Attr.Type == null ? "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAttractionsAmexVendorDetails(" + Attr.GroupID + "," + Attr.VendorID + "," + 2 + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + "Attractions" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>"
                                                                               : "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAttractionsAmexVendorDetails(" + Attr.GroupID + "," + Attr.VendorID + "," + 2 + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + "Restaurants" + "\"" + "," + "\"" + Attr.Type + "\"" + ")'>Detail</button></div>",
                        AttractionsPayMeth3FormHtml = Attr.Type == null ? "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAttractionsAmexVendorDetails(" + Attr.GroupID + "," + Attr.VendorID + "," + 3 + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + "Attractions" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>"
                                                                               : "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAttractionsAmexVendorDetails(" + Attr.GroupID + "," + Attr.VendorID + "," + 3 + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + "Restaurants" + "\"" + "," + "\"" + Attr.Type + "\"" + ")'>Detail</button></div>",
                        AttractionsOptionalFormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationAttractionsOptionalDetails(" + Attr.GroupID + "," + Attr.VendorID + "," + "\"" + Convert.ToDateTime(Attr.StartDate).ToString() + "\"" + "," + "\"" + Attr.Type + "\"" + ")'>Optional</button></div>",
                        AttractionsQuotaSupplier = Attr.QuotaVendorName,
                        AttractionsQuotaCurr = QuotaCurrency,
                        AttractionsQuotaPrice = Attr.QuotaRate != null ? Convert.ToDecimal(Attr.QuotaRate).ToString("F") : "0",
                    });
                    if (QuotaCurrency == "CAD")
                    {
                        CADTotalPaidSum = CADTotalPaidSum + TotalPaid;
                        CADDifferenceSum = CADDifferenceSum + Difference * Convert.ToInt32(Attr.NumOfPerson);
                        CADOutstandingAmtSum = CADOutstandingAmtSum + OutstandingAmt;
                        CADTotalDiffPaidChargedSum = CADTotalDiffPaidChargedSum + DifferenceTotalPaid_TotalCharged;
                        CADTotalCostSum += TotalCost;
                    }
                    else if (QuotaCurrency == "USD")
                    {
                        TotalPaidSum = TotalPaidSum + TotalPaid;
                        DifferenceSum = DifferenceSum + Difference * Convert.ToInt32(Attr.NumOfPerson);
                        OutstandingAmtSum = OutstandingAmtSum + OutstandingAmt;
                        TotalDiffPaidChargedSum = TotalDiffPaidChargedSum + DifferenceTotalPaid_TotalCharged;
                        TotalCostSum += TotalCost;
                    }        
                }
            // Calc Group Profit
            if (AttractionsData.SearchGroupCode != null)
            {
                OperAttractionsGridView.AttractionsTotCost = TotalCostSum;
                OperAttractionsGridView.AttractionsTotCostCad = CADTotalCostSum;
                OperAttractionsGridView.AttractionsGroupProfit = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='AttractionsGroupProfit'></span><span class='OperationSumCAD GrpProfit' id='AttractionsGroupProfitCad'></span></label>";
                OperAttractionsGridView.AttractionsTotInvoice = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='AttractionsTotInv'></span><span class='OperationSumCAD GrpProfit' id='AttractionsTotInvCAD'></span></label>";
                OperAttractionsGridView.AttractionsProfitPers = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='AttractionsProfitPers'></span><span class='OperationSumCAD GrpProfit' id='AttractionsProfitPersCAD'></span></label>";
            }
            // Attractions Total
            OperAttractionsGridView.AttractionsTotalPaidSum = "<label class='form-control'>" + (TotalPaidSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + TotalPaidSum.ToString("F") + " USD" + (CADTotalPaidSum == 0 ? "" : ",") + "</span>" + (CADTotalPaidSum == 0 ? "" : (CADTotalPaidSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADTotalPaidSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperAttractionsGridView.AttractionsDifferenceSum = "<label class='form-control'>" + (DifferenceSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + DifferenceSum.ToString("F") + " USD" + (CADDifferenceSum == 0 ? "" : ",") + "</span>" + (CADDifferenceSum == 0 ? "" : (CADDifferenceSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADDifferenceSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperAttractionsGridView.AttractionsOutstandingAmtSum = "<label class='form-control'>" + (OutstandingAmtSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + OutstandingAmtSum.ToString("F") + " USD" + (CADOutstandingAmtSum == 0 ? "" : ",") + "</span>" + (CADOutstandingAmtSum == 0 ? "" : (CADOutstandingAmtSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADOutstandingAmtSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperAttractionsGridView.AttractionsTotalDiffPaidChargedSum = "<label class='form-control'>" + (TotalDiffPaidChargedSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + TotalDiffPaidChargedSum.ToString("F") + " USD" + (CADTotalDiffPaidChargedSum == 0 ? "" : ",") + "</span>" + (CADTotalDiffPaidChargedSum == 0 ? "" : (CADTotalDiffPaidChargedSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADTotalDiffPaidChargedSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperAttractionsGridView.AttractionsTotalCostAmtSum = "<label class='form-control'>" + (TotalCostSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + TotalCostSum.ToString("F") + " USD" + (CADTotalCostSum == 0 ? "" : ",") + "</span>" + (CADTotalCostSum == 0 ? "" : (CADTotalCostSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADTotalCostSum.ToString("F") + " CAD" + "</span>") + "</label>";
            // Group Code filter
            OperAttractionsGridView.AttractionsFilterGroupCode = new List<CheckBoxControlViewModel>();
            OperAttractionsGridView.AttractionsFilterSelGroupCode = new List<CheckBoxControlViewModel>();
            // Group Name filter
            OperAttractionsGridView.AttractionsFilterGroupName = new List<CheckBoxControlViewModel>();
            OperAttractionsGridView.AttractionsFilterSelGroupName = new List<CheckBoxControlViewModel>();
            // Customer filter
            OperAttractionsGridView.AttractionsFilterCustomerCode = new List<CheckBoxControlViewModel>();
            OperAttractionsGridView.AttractionsFilterSelCustomerCode = new List<CheckBoxControlViewModel>();
            // Status filter
            OperAttractionsGridView.AttractionsFilterStatus = new List<CheckBoxControlViewModel>();
            OperAttractionsGridView.AttractionsFilterSelStatus = new List<CheckBoxControlViewModel>();
            // Vendor Name filter
            OperAttractionsGridView.AttractionsFilterVendorName = new List<CheckBoxControlViewModel>();
            OperAttractionsGridView.AttractionsFilterSelVendorName = new List<CheckBoxControlViewModel>();
            // Vendor Type filter
            OperAttractionsGridView.AttractionsFilterVendorType = new List<CheckBoxControlViewModel>();
            OperAttractionsGridView.AttractionsFilterSelVendorType = new List<CheckBoxControlViewModel>();
            // Vendor City filter
            OperAttractionsGridView.AttractionsFilterVendorCity = new List<CheckBoxControlViewModel>();
            OperAttractionsGridView.AttractionsFilterSelVendorCity = new List<CheckBoxControlViewModel>();
            // Restaurant type filter
            OperAttractionsGridView.AttractionsFilterRestaurantType = new List<CheckBoxControlViewModel>();
            OperAttractionsGridView.AttractionsFilterSelRestaurantType = new List<CheckBoxControlViewModel>();
            // Group Code filter init
            if (AttractionsData != null && AttractionsData.FilterGroupCode != null)
                foreach (var grp in AttractionsData.FilterGroupCode)
                {
                    OperAttractionsGridView.AttractionsFilterGroupCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Group Name filter init
            if (AttractionsData != null && AttractionsData.FilterGroupName != null)
                foreach (var grp in AttractionsData.FilterGroupName)
                {
                    OperAttractionsGridView.AttractionsFilterGroupName.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Customer filter init
            if (AttractionsData != null && AttractionsData.FilterCustomerCode != null)
                foreach (var grp in AttractionsData.FilterCustomerCode)
                {
                    OperAttractionsGridView.AttractionsFilterCustomerCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Status filter init
            if (AttractionsData != null && AttractionsData.FilterVendorStatus != null)
                foreach (var grp in AttractionsData.FilterVendorStatus)
                {
                    OperAttractionsGridView.AttractionsFilterStatus.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Vendor Name filter init
            if (AttractionsData != null && AttractionsData.FilterVendorName != null)
                foreach (var grp in AttractionsData.FilterVendorName)
                {
                    OperAttractionsGridView.AttractionsFilterVendorName.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Vendor Type filter init
            if (AttractionsData != null && AttractionsData.FilterVendorType != null)
                foreach (var grp in AttractionsData.FilterVendorType)
                {
                    OperAttractionsGridView.AttractionsFilterVendorType.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Vendor City filter init
            if (AttractionsData != null && AttractionsData.FilterVendorCity != null)
                foreach (var grp in AttractionsData.FilterVendorCity)
                {
                    OperAttractionsGridView.AttractionsFilterVendorCity.Add(new CheckBoxControlViewModel { Id = grp, Name = grp });
                }
            // Restaurant Type filter init
            if (AttractionsData != null && AttractionsData.FilterRestaurantType != null)
                foreach (var grp in AttractionsData.FilterRestaurantType)
                {
                    OperAttractionsGridView.AttractionsFilterRestaurantType.Add(new CheckBoxControlViewModel { Id = grp, Name = grp });
                }
        }
        private void InitMiscGridViewData(OperationMiscGridBData MiscData, OperationMiscGridViewModel OperMiscGridView)
        {
            OperMiscGridView.Rows = new List<OperationMiscGridRowViewModel>();
            OperMiscGridView.VendorInfo = new List<OperationMiscVendorInfoViewModel>();
            OperMiscGridView.VendorStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            OperMiscGridView.Employee = new List<System.Web.WebPages.Html.SelectListItem>();
            OperMiscGridView.Details = new List<System.Web.WebPages.Html.SelectListItem>();
            OperMiscGridView.PaymentMethod = new List<System.Web.WebPages.Html.SelectListItem>();
            // Pay method init
            if (MiscData != null && MiscData.PayMethod != null)
                foreach (var pay in MiscData.PayMethod)
                {
                    OperMiscGridView.PaymentMethod.Add(new System.Web.WebPages.Html.SelectListItem { Text = pay.Value, Value = pay.Key.ToString() });
                }
            // VendorInfo init
            if (MiscData != null && MiscData.VendorInfo != null)
                foreach (var vnd in MiscData.VendorInfo)
                {
                    OperMiscGridView.VendorInfo.Add(new OperationMiscVendorInfoViewModel
                    {
                        VendorID = vnd.VendorID,
                        VendorAddress = vnd.VendorAddress,
                        VendorName = vnd.VendorName,
                        VendorCity = vnd.VendorCity,
                        VendorContactPerson = vnd.VendorContactPerson,
                        VendorEmail = vnd.VendorEmail,
                        VendorPhone = vnd.VendorPhone,
                        VendorType = vnd.VendorType,
                        VendorIsFind = vnd.IsFind == null ? false : Convert.ToBoolean(vnd.IsFind),
                    });
                }
            if (MiscData != null && MiscData.VendorStatus != null)
                foreach (var status in MiscData.VendorStatus)
                {
                    OperMiscGridView.VendorStatus.Add(new System.Web.WebPages.Html.SelectListItem() { Text = status.Value, Value = status.Key.ToString() });
                }
            // details init
            if (MiscData != null && MiscData.DetailCode != null)
                foreach (var det in MiscData.DetailCode)
                {
                    OperMiscGridView.Details.Add(new System.Web.WebPages.Html.SelectListItem { Text = det.Value, Value = det.Key.ToString() });
                }
            // employee init
            if (MiscData != null && MiscData.Employee != null)
                foreach (var emp in MiscData.Employee)
                {
                    OperMiscGridView.Employee.Add(new System.Web.WebPages.Html.SelectListItem { Text = emp.Value, Value = emp.Key.ToString() });
                }
            decimal TotalPaidSum = 0;
            decimal DifferenceSum = 0;
            decimal PGDifferenceSum = 0;
            decimal CompSum = 0;
            decimal PGCompSum = 0;
            decimal TotalCostSum = 0;
            decimal OutstandingAmtSum = 0;
            decimal CADTotalPaidSum = 0;
            decimal CADDifferenceSum = 0;
            decimal CADPGDifferenceSum = 0;
            decimal CADCompSum = 0;
            decimal CADPGCompSum = 0;
            decimal CADTotalCostSum = 0;
            decimal CADOutstandingAmtSum = 0;
            if (MiscData != null && MiscData.Rows != null)
                foreach (var Misc in MiscData.Rows)
                {
                    string ContractGroupPath = Misc.MiscGroupContractPath != null ? System.Configuration.ConfigurationManager.AppSettings["UploadVendorConfirmContract"] + Misc.MiscGroupContractPath : null;
                    string QuotaCurrency = Misc.QuotaCurrency == null ? "USD" : (Misc.QuotaCurrency == "US" || Misc.QuotaCurrency == "USD") ? "USD" : (Misc.QuotaCurrency == "CA" || Misc.QuotaCurrency == "CAD") ? "CAD" : "";

                    decimal Difference = Convert.ToDecimal(Misc.QuotaRate) - Convert.ToDecimal(Misc.UnitPrice);
                    decimal PGDifference = Convert.ToDecimal(Misc.QuotaGrpRate) - Convert.ToDecimal(Misc.UnitPricePG);
                    decimal TotalPaid = Convert.ToDecimal(Misc.FirstPayAmt) + Convert.ToDecimal(Misc.SecondPayAmt) + Convert.ToDecimal(Misc.ThirdPayAmt);
                    decimal TotalCost = Convert.ToDecimal(Misc.UnitPrice) * Convert.ToInt32(Misc.NumOfPerson) + Convert.ToDecimal(Misc.UnitPricePG);
                    decimal OutstandingAmt = TotalPaid - TotalCost;

                    OperMiscGridView.Rows.Add(new OperationMiscGridRowViewModel()
                    {
                        MiscGroupID = Misc.GroupID.ToString(),
                        MiscVendorID = Misc.VendorID,
                        MiscGroupCode = Misc.GroupCode,
                        MiscGroupName = Misc.GroupName,
                        MiscSelectedEmployee = MiscData.Employee.Any(emp => emp.Key == Misc.EmployeeID) ? MiscData.Employee.Where(emp => emp.Key == Misc.EmployeeID).SingleOrDefault().Value : null,
                        MiscSelectedDetail = MiscData.DetailCode.Any(det => det.Key == Misc.ServiceDetID) ? MiscData.DetailCode.Where(det => det.Key == Misc.ServiceDetID).SingleOrDefault().Value : null,
                        MiscPax = Misc.NumOfPerson.ToString(),
                        MiscEstNoOfPerson = Misc.EstNumOfPerson.ToString(),
                        MiscCustomer = Misc.Customer,
                        MiscCity = Misc.VendorCity,
                        MiscAddress = Misc.VendorAddress,
                        MiscUnitPrice = Misc.UnitPrice != null ? Convert.ToDecimal(Misc.UnitPrice).ToString("F") : "0",
                        MiscUnitPricePG = Misc.UnitPricePG != null ? Convert.ToDecimal(Misc.UnitPricePG).ToString("F") : "0",
                        MiscTotalAmountPaid = TotalPaid.ToString("F"),
                        MiscTotalCost = TotalCost.ToString("F"),
                        MiscOutstandingAmt = OutstandingAmt.ToString("F"),
                        MiscDiff = Difference.ToString("F"),
                        MiscPGDiff = PGDifference.ToString("F"),
                        MiscEmail = Misc.VendorEmail,
                        MiscPhone = Misc.VendorPhone,
                        MiscSupplier = Misc.VendorName,
                        MiscPlane = Misc.Plane != null ? Convert.ToBoolean(Misc.Plane) : false,
                        MiscIsComp = Misc.IsComp != null ? Convert.ToBoolean(Misc.IsComp) : false,
                        MiscSelectedVendorStatus = Misc.VendorSelStatus,
                        MiscDate = (Convert.ToDateTime(Misc.StartDate)).ToString("ddd, dd/MMM/yy"),
                        MiscTime = Misc.Time != null ? Convert.ToDateTime(Misc.Time).ToString("HH:mm") : "",
                        MiscContact = Misc.VendorContactName,
                        MiscGroupContractHtml = "<div style='text-align:center;'><button class='btn14 btn120 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationVendorContractDetails(" + "\"" + ContractGroupPath + "\"" + ")'>Vendor Contract</button></div>",
                        MiscConfHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='OperGroupMiscConfLoad(" + Misc.GroupID + "," + Misc.VendorID + "," + "\"" + Convert.ToDateTime(Misc.StartDate).ToString() + "\"" + "," + "\"" + "Misc" + "\"" + ")'>Details</button></div>",
                        MiscNotes = Misc.Notes,
                        MiscQuotaSupplier = Misc.QuotaVendorName,
                        MiscQuotaCurr = QuotaCurrency,
                        MiscQuotaPrice = Misc.QuotaRate != null ? Convert.ToDecimal(Misc.QuotaRate).ToString("F") : "0",
                        MiscQuotaPerGroupPrice = Misc.QuotaGrpRate != null ? Convert.ToDecimal(Misc.QuotaGrpRate).ToString("F") : "0",
                        MiscDateFirstPayment = Misc.FirstPayDate != null ? Convert.ToDateTime(Misc.FirstPayDate).ToString("dd/MMM/yyyy") : "",
                        MiscSelectedFirstPaymentMethod = Misc.FirstPayMethod,
                        MiscFirstPayment = Misc.FirstPayAmt != null ? Convert.ToDecimal(Misc.FirstPayAmt).ToString("F") : "0",
                        MiscDateSecondPayment = Misc.SecondPayDate != null ? Convert.ToDateTime(Misc.SecondPayDate).ToString("dd/MMM/yyyy") : "",
                        MiscSelectedSecondPaymentMethod = Misc.SecondPayMethod,
                        MiscSecondPayment = Misc.SecondPayAmt != null ? Convert.ToDecimal(Misc.SecondPayAmt).ToString("F") : "0",
                        MiscDateThirdPayment = Misc.ThirdPayDate != null ? Convert.ToDateTime(Misc.ThirdPayDate).ToString("dd/MMM/yyyy") : "",
                        MiscSelectedThirdPaymentMethod = Misc.ThirdPayMethod,
                        MiscThirdPayment = Misc.ThirdPayAmt != null ? Convert.ToDecimal(Misc.ThirdPayAmt).ToString("F") : "0",
                        MiscPayMeth1FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationMiscAmexVendorDetails(" + Misc.GroupID + "," + Misc.VendorID + "," + 1 + "," + "\"" + Convert.ToDateTime(Misc.StartDate).ToString() + "\"" + "," + "\"" + "Misc" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                        MiscPayMeth2FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationMiscAmexVendorDetails(" + Misc.GroupID + "," + Misc.VendorID + "," + 2 + "," + "\"" + Convert.ToDateTime(Misc.StartDate).ToString() + "\"" + "," + "\"" + "Misc" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                        MiscPayMeth3FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationMiscAmexVendorDetails(" + Misc.GroupID + "," + Misc.VendorID + "," + 3 + "," + "\"" + Convert.ToDateTime(Misc.StartDate).ToString() + "\"" + "," + "\"" + "Misc" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                    });
                    if (QuotaCurrency == "CAD")
                    {
                        CADTotalPaidSum = CADTotalPaidSum + TotalPaid;
                        CADTotalCostSum = CADTotalCostSum + TotalCost;
                        CADOutstandingAmtSum = CADOutstandingAmtSum + OutstandingAmt;
                        CADDifferenceSum = CADDifferenceSum + Difference * Convert.ToInt32(Misc.NumOfPerson);
                        CADPGDifferenceSum = CADPGDifferenceSum + PGDifference;
                        CADCompSum = CADCompSum + (Misc.IsComp == true ? Convert.ToDecimal(Misc.UnitPrice) * Convert.ToInt32(Misc.NumOfPerson) : 0);
                        CADPGCompSum = CADPGCompSum + (Misc.IsComp == true ? Convert.ToDecimal(Misc.UnitPricePG) : 0);
                    }
                    else if (QuotaCurrency == "USD")
                    {
                        TotalPaidSum = TotalPaidSum + TotalPaid;
                        TotalCostSum = TotalCostSum + TotalCost;
                        OutstandingAmtSum = OutstandingAmtSum + OutstandingAmt;
                        DifferenceSum = DifferenceSum + Difference * Convert.ToInt32(Misc.NumOfPerson);
                        PGDifferenceSum = PGDifferenceSum + PGDifference;
                        CompSum = CompSum + (Misc.IsComp == true ? Convert.ToDecimal(Misc.UnitPrice) * Convert.ToInt32(Misc.NumOfPerson) : 0);
                        PGCompSum = PGCompSum + (Misc.IsComp == true ? Convert.ToDecimal(Misc.UnitPricePG) : 0);
                    }    
                }
            // Calc Group Profit
            if (MiscData.SearchGroupCode != null)
            {
                OperMiscGridView.MiscTotCost = TotalCostSum;
                OperMiscGridView.MiscTotCostCad = CADTotalCostSum;
                OperMiscGridView.MiscGroupProfit = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='MiscGroupProfit'></span><span class='OperationSumCAD GrpProfit' id='MiscGroupProfitCad'></span></label>";
                OperMiscGridView.MiscTotInvoice = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='MiscTotInv'></span><span class='OperationSumCAD GrpProfit' id='MiscTotInvCAD'></span></label>";
                OperMiscGridView.MiscProfitPers = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='MiscProfitPers'></span><span class='OperationSumCAD GrpProfit' id='MiscProfitPersCAD'></span></label>";
            }
            // Misc Total
            OperMiscGridView.MiscTotalPaidSum = "<label class='form-control'>" + (TotalPaidSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + TotalPaidSum.ToString("F") + " USD" + (CADTotalPaidSum == 0 ? "" : ",") + "</span>" + (CADTotalPaidSum == 0 ? "" : (CADTotalPaidSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADTotalPaidSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperMiscGridView.MiscTotalCostAmtSum = "<label class='form-control'>" + (TotalCostSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + TotalCostSum.ToString("F") + " USD" + (CADTotalCostSum == 0 ? "" : ",") + "</span>" + (CADTotalCostSum == 0 ? "" : (CADTotalCostSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADTotalCostSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperMiscGridView.MiscOutstandingAmtSum = "<label class='form-control'>" + (OutstandingAmtSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + OutstandingAmtSum.ToString("F") + " USD" + (CADOutstandingAmtSum == 0 ? "" : ",") + "</span>" + (CADOutstandingAmtSum == 0 ? "" : (CADOutstandingAmtSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADOutstandingAmtSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperMiscGridView.MiscDifferenceSum = "<label class='form-control'>" + (DifferenceSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + DifferenceSum.ToString("F") + " USD" + (CADDifferenceSum == 0 ? "" : ",") + "</span>" + (CADDifferenceSum == 0 ? "" : (CADDifferenceSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADDifferenceSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperMiscGridView.MiscPGDifferenceSum = "<label class='form-control'>" + (PGDifferenceSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + PGDifferenceSum.ToString("F") + " USD" + (CADPGDifferenceSum == 0 ? "" : ",") + "</span>" + (CADPGDifferenceSum == 0 ? "" : (CADPGDifferenceSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADPGDifferenceSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperMiscGridView.MiscCompSum = "<label class='form-control'>" + "<span class='OperationSumUSD SumControls10Size'>" + CompSum.ToString("F") + " USD" + (CADCompSum == 0 ? "" : ",") + "</span>" + (CADCompSum == 0 ? "" : "<span class='OperationSumCAD SumControls10Size'>" + CADCompSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperMiscGridView.MiscPGCompSum = "<label class='form-control'>" + "<span class='OperationSumUSD SumControls10Size'>" + PGCompSum.ToString("F") + " USD" + (CADPGCompSum == 0 ? "" : ",") + "</span>" + (CADPGCompSum == 0 ? "" : "<span class='OperationSumCAD SumControls10Size'>" + CADPGCompSum.ToString("F") + " CAD" + "</span>") + "</label>";
            // Group Code filter
            OperMiscGridView.MiscFilterGroupCode = new List<CheckBoxControlViewModel>();
            OperMiscGridView.MiscFilterSelGroupCode = new List<CheckBoxControlViewModel>();
            // Group Name filter
            OperMiscGridView.MiscFilterGroupName = new List<CheckBoxControlViewModel>();
            OperMiscGridView.MiscFilterSelGroupName = new List<CheckBoxControlViewModel>();
            // Customer filter
            OperMiscGridView.MiscFilterCustomerCode = new List<CheckBoxControlViewModel>();
            OperMiscGridView.MiscFilterSelCustomerCode = new List<CheckBoxControlViewModel>();
            // Status filter
            OperMiscGridView.MiscFilterStatus = new List<CheckBoxControlViewModel>();
            OperMiscGridView.MiscFilterSelStatus = new List<CheckBoxControlViewModel>();
            // Vendor Name filter
            OperMiscGridView.MiscFilterVendorName = new List<CheckBoxControlViewModel>();
            OperMiscGridView.MiscFilterSelVendorName = new List<CheckBoxControlViewModel>();
            // Vendor City filter
            OperMiscGridView.MiscFilterVendorCity = new List<CheckBoxControlViewModel>();
            OperMiscGridView.MiscFilterSelVendorCity = new List<CheckBoxControlViewModel>();
            // Group Code filter init
            if (MiscData != null && MiscData.FilterGroupCode != null)
                foreach (var grp in MiscData.FilterGroupCode)
                {
                    OperMiscGridView.MiscFilterGroupCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Group Name filter init
            if (MiscData != null && MiscData.FilterGroupName != null)
                foreach (var grp in MiscData.FilterGroupName)
                {
                    OperMiscGridView.MiscFilterGroupName.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Customer filter init
            if (MiscData != null && MiscData.FilterCustomerCode != null)
                foreach (var grp in MiscData.FilterCustomerCode)
                {
                    OperMiscGridView.MiscFilterCustomerCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Status filter init
            if (MiscData != null && MiscData.FilterVendorStatus != null)
                foreach (var grp in MiscData.FilterVendorStatus)
                {
                    OperMiscGridView.MiscFilterStatus.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Vendor Name filter init
            if (MiscData != null && MiscData.FilterVendorName != null)
                foreach (var grp in MiscData.FilterVendorName)
                {
                    OperMiscGridView.MiscFilterVendorName.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Vendor City filter init
            if (MiscData != null && MiscData.FilterVendorCity != null)
                foreach (var grp in MiscData.FilterVendorCity)
                {
                    OperMiscGridView.MiscFilterVendorCity.Add(new CheckBoxControlViewModel { Id = grp, Name = grp });
                }
        }
        private void InitBusGridViewData(OperationBusGridBData BusData, OperationBusGridViewModel OperBusGridView)
        {
            OperBusGridView.Rows = new List<OperationBusGridRowViewModel>();
            OperBusGridView.Details = new List<OperationBusDetailInfoViewModel>();
            OperBusGridView.Services = new List<OperationBusServiceInfoViewModel>();
            OperBusGridView.Employee = new List<System.Web.WebPages.Html.SelectListItem>();
            OperBusGridView.VendorInfo = new List<OperationBusVendorInfoViewModel>();
            OperBusGridView.GuideInfo = new List<OperationBusGuideInfoViewModel>();
            OperBusGridView.VendorStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            OperBusGridView.PaymentMethod = new List<System.Web.WebPages.Html.SelectListItem>();
            // Pay method init
            if (BusData != null && BusData.PayMethod != null)
                foreach (var pay in BusData.PayMethod)
                {
                    OperBusGridView.PaymentMethod.Add(new System.Web.WebPages.Html.SelectListItem { Text = pay.Value, Value = pay.Key.ToString() });
                }
            // VendorInfo init
            if (BusData != null && BusData.VendorInfo != null)
                foreach (var vnd in BusData.VendorInfo)
                {
                    OperBusGridView.VendorInfo.Add(new OperationBusVendorInfoViewModel
                    {
                        VendorID = vnd.VendorID,
                        VendorAddress = vnd.VendorAddress,
                        VendorName = vnd.VendorName,
                        VendorCity = vnd.VendorCity,
                        VendorContactPerson = vnd.VendorContactPerson,
                        VendorEmail = vnd.VendorEmail,
                        VendorPhone = vnd.VendorPhone,
                        VendorType = vnd.VendorType,
                        VendorIsFind = vnd.IsFind == null ? false : Convert.ToBoolean(vnd.IsFind),
                    });
                }
            // GuideInfo init
            if (BusData != null && BusData.GuideInfo != null)
                foreach (var guide in BusData.GuideInfo)
                {
                    OperBusGridView.GuideInfo.Add(new OperationBusGuideInfoViewModel
                    {
                        GuideID = guide.GuideID,
                        GuideName = guide.GuideName,
                    });
                }
            if (BusData != null && BusData.VendorStatus != null)
                foreach (var status in BusData.VendorStatus)
                {
                    OperBusGridView.VendorStatus.Add(new System.Web.WebPages.Html.SelectListItem() { Text = status.Value, Value = status.Key.ToString() });
                }
            // details init
            if (BusData != null && BusData.DetailCode != null)
                foreach (var det in BusData.DetailCode)
                {
                    OperBusGridView.Details.Add(new OperationBusDetailInfoViewModel { DetailID = det.Key, DetailCode = det.Value.DetailCode, ServiceTypeID = (int)det.Value.ServiceTypeID });
                }
            // Services init
            if (BusData != null && BusData.Service != null)
                foreach (var srv in BusData.Service)
                {
                    OperBusGridView.Services.Add(new OperationBusServiceInfoViewModel { ServiceID = srv.ServiceID, ServiceCode = srv.ServiceCode, ServiceTypeID = (int)srv.ServiceTypeID });
                }
            // employee init
            if (BusData != null && BusData.Employee != null)
                foreach (var emp in BusData.Employee)
                {
                    OperBusGridView.Employee.Add(new System.Web.WebPages.Html.SelectListItem { Text = emp.Value, Value = emp.Key.ToString() });
                }
            decimal GuideTotalCostSum = 0;
            decimal BusTotalCostSum = 0;
            decimal GuideTotalPaidSum = 0;
            decimal BusTotalPaidSum = 0;
            decimal GuideDifferenceSum = 0;
            decimal BusDifferenceSum = 0;
            decimal GuideMiscDifferenceSum = 0;
            decimal GuideStepOnDifferenceSum = 0;
            decimal CADGuideTotalCostSum = 0;
            decimal CADBusTotalCostSum = 0;
            decimal CADGuideTotalPaidSum = 0;
            decimal CADBusTotalPaidSum = 0;
            decimal CADGuideDifferenceSum = 0;
            decimal CADBusDifferenceSum = 0;
            decimal CADGuideMiscDifferenceSum = 0;
            decimal CADGuideStepOnDifferenceSum = 0;
            if (BusData != null && BusData.Rows != null)
                foreach (var bus in BusData.Rows)
                {
                    string ContractGroupPath = bus.BusGroupContractPath != null ? System.Configuration.ConfigurationManager.AppSettings["UploadVendorConfirmContract"] + bus.BusGroupContractPath : null;
                    decimal GuideTotalCost = Convert.ToDecimal(bus.GuideSalary) + Convert.ToDecimal(bus.GuideMisc) + Convert.ToDecimal(bus.GuideStepOn);
                    decimal BusTotalCost = Convert.ToDecimal(bus.BusPrice) * Convert.ToInt32(bus.BusCount);
                    decimal GuideTotalPaid = Convert.ToDecimal(bus.GuideFirstPayAmt) + Convert.ToDecimal(bus.GuideSecondPayAmt) + Convert.ToDecimal(bus.GuideThirdPayAmt);
                    decimal BusTotalPaid = Convert.ToDecimal(bus.FirstPayAmt) + Convert.ToDecimal(bus.SecondPayAmt) + Convert.ToDecimal(bus.ThirdPayAmt);
                    decimal GuideDifference = Convert.ToDecimal(bus.QuotaGuideRate) - Convert.ToDecimal(bus.GuideSalary);
                    decimal BusDifference = Convert.ToDecimal(bus.QuotaBusRate) - Convert.ToDecimal(bus.BusPrice);
                    decimal GuideMiscDifference = Convert.ToDecimal(bus.QuotaGuideMisc) - Convert.ToDecimal(bus.GuideMisc);
                    decimal GuideStepOnDifference = Convert.ToDecimal(bus.QuotaGuideStepOn) - Convert.ToDecimal(bus.GuideStepOn);
                    string QuotaBusCurrency = bus.QuotaBusCurr == null ? "USD" : (bus.QuotaBusCurr == "US" || bus.QuotaBusCurr == "USD") ? "USD" : (bus.QuotaBusCurr == "CA" || bus.QuotaBusCurr == "CAD") ? "CAD" : "";
                    string QuotaGuideCurrency = bus.QuotaGuideCurr == null ? "USD" : (bus.QuotaGuideCurr == "US" || bus.QuotaGuideCurr == "USD") ? "USD" : (bus.QuotaGuideCurr == "CA" || bus.QuotaGuideCurr == "CAD") ? "CAD" : "";
                    OperBusGridView.Rows.Add(new OperationBusGridRowViewModel()
                    {
                        BusIsInvoice = bus.IsInvoice != null ? Convert.ToBoolean(bus.IsInvoice) : false,
                        BusInvoicePrice = bus.InvoicePrice != null ? Convert.ToDecimal(bus.InvoicePrice).ToString("F") : "0",
                        BusGroupID = bus.GroupID,
                        BusGroupCode = bus.GroupCode,
                        BusGroupName = bus.GroupName,
                        BusCustomer = bus.Customer,
                        BusPax = bus.NumOfPerson.ToString(),
                        BusEstNoOfPerson = bus.EstNumOfPerson.ToString(),
                        BusStart = bus.BusStartDate.ToString("ddd, dd/MMM/yy"),
                        BusTime = bus.BusTime != null ? Convert.ToDateTime(bus.BusTime).ToString("HH:mm") : "",
                        BusDateOfService = bus.ServiceDate != null ? Convert.ToDateTime(bus.ServiceDate).ToString("ddd, dd/MMM/yy") : "",
                        BusStartCity = bus.StartCity,
                        BusEndCity = bus.EndCity,
                        BusBusCount = bus.BusCount.ToString(),
                        BusBusSize = bus.BusSize.ToString(),
                        BusGuideTotalCost = GuideTotalCost.ToString("F"),
                        BusBusTotalCost = BusTotalCost.ToString("F"),
                        BusGuideTotalPaid = GuideTotalPaid.ToString("F"),
                        BusBusTotalPaid = BusTotalPaid.ToString("F"),
                        BusGuideDifference = GuideDifference.ToString("F"),
                        BusGuideMiscDifference = GuideMiscDifference.ToString("F"),
                        BusGuideStepOnDifference = GuideStepOnDifference.ToString("F"),
                        BusBusDifference = BusDifference.ToString("F"),
                        BusAirport = bus.Airport,
                        BusStatus = bus.VendorSelStatus,
                        BusSelectedService = BusData.Service.Any(srv => srv.ServiceID == bus.ServiceID) ? BusData.Service.Where(srv => srv.ServiceID == bus.ServiceID).SingleOrDefault().ServiceCode : null,
                        BusSelectedDetail = BusData.DetailCode.Any(det => det.Key == bus.ServiceDetID) ? BusData.DetailCode.Where(det => det.Key == bus.ServiceDetID).SingleOrDefault().Value.DetailCode : null,
                        BusSelectedEmployee = BusData.Employee.Any(emp => emp.Key == bus.EmployeeID) ? BusData.Employee.Where(emp => emp.Key == bus.EmployeeID).SingleOrDefault().Value : null,
                        BusSupplier = bus.Supplier,
                        BusQuotaBusCurr = QuotaBusCurrency,
                        BusQuotaBusPrice = bus.QuotaBusRate != null ? Convert.ToDecimal(bus.QuotaBusRate).ToString("F") : "0",
                        BusQuotaVendorID = bus.QuotaVendorID.ToString(),
                        BusQuotaSupplier = bus.QuotaBusSupplier,
                        BusQuotaGuideCurr = QuotaGuideCurrency,
                        BusQuotaGuideSalary = bus.QuotaGuideRate != null ? Convert.ToDecimal(bus.QuotaGuideRate).ToString("F") : "0",
                        BusQuotaGuideMisc = bus.QuotaGuideMisc != null ? Convert.ToDecimal(bus.QuotaGuideMisc).ToString("F") : "0",
                        BusQuotaGuideStepOn = bus.QuotaGuideStepOn != null ? Convert.ToDecimal(bus.QuotaGuideStepOn).ToString("F") : "0",
                        BusQuotaGuideID = bus.QuotaGuideID.ToString(),
                        BusQuotaGuide = bus.QuotaGuide,
                        BusGuide = bus.Guide,
                        BusGuideSalary = bus.GuideSalary != null ? Convert.ToDecimal(bus.GuideSalary).ToString("F") : "0",
                        BusGuideMisc = bus.GuideMisc != null ? Convert.ToDecimal(bus.GuideMisc).ToString("F") : "0",
                        BusGuideStepOn = bus.GuideStepOn != null ? Convert.ToDecimal(bus.GuideStepOn).ToString("F") : "0",
                        BusGuideSalaryPaid = bus.GuideSalaryPaid != null ? Convert.ToDecimal(bus.GuideSalaryPaid).ToString("F") : "0",
                        BusGuideSalaryInvoicePaid = bus.GuidePaidAmt != null ? Convert.ToDecimal(bus.GuidePaidAmt).ToString("F") : "0",
                        BusGuideAdditionalCharges = bus.GuideAddCharge != null ? Convert.ToDecimal(bus.GuideAddCharge).ToString("F") : "0",
                        BusCost = bus.Cost != null ? Convert.ToDecimal(bus.Cost).ToString("F") : "0",
                        BusPrice = bus.BusPrice != null ? Convert.ToDecimal(bus.BusPrice).ToString("F") : "0",
                        BusVendorID = bus.VendorID,
                        BusNotes = bus.Notes,
                        BusGuideID = bus.GuideID == null ? 0 : Convert.ToInt32(bus.GuideID),
                        BusGuideStart = bus.GuideStartDate != null ? Convert.ToDateTime(bus.GuideStartDate).ToString("ddd, dd/MMM/yy") : "",
                        BusDateFirstPayment = bus.FirstPayDate != null ? Convert.ToDateTime(bus.FirstPayDate).ToString("dd/MMM/yyyy") : "",
                        BusSelectedFirstPaymentMethod = bus.FirstPayMethod,
                        BusFirstPayment = bus.FirstPayAmt != null ? Convert.ToDecimal(bus.FirstPayAmt).ToString("F") : "0",
                        BusDateSecondPayment = bus.SecondPayDate != null ? Convert.ToDateTime(bus.SecondPayDate).ToString("dd/MMM/yyyy") : "",
                        BusSelectedSecondPaymentMethod = bus.SecondPayMethod,
                        BusSecondPayment = bus.SecondPayAmt != null ? Convert.ToDecimal(bus.SecondPayAmt).ToString("F") : "0",
                        BusDateThirdPayment = bus.ThirdPayDate != null ? Convert.ToDateTime(bus.ThirdPayDate).ToString("dd/MMM/yyyy") : "",
                        BusSelectedThirdPaymentMethod = bus.ThirdPayMethod,
                        BusThirdPayment = bus.ThirdPayAmt != null ? Convert.ToDecimal(bus.ThirdPayAmt).ToString("F") : "0",
                        BusGuideDateFirstPayment = bus.GuideFirstPayDate != null ? Convert.ToDateTime(bus.GuideFirstPayDate).ToString("dd/MMM/yyyy") : "",
                        BusGuideSelectedFirstPaymentMethod = bus.GuideFirstPayMethod,
                        BusGuideFirstPayment = bus.GuideFirstPayAmt != null ? Convert.ToDecimal(bus.GuideFirstPayAmt).ToString("F") : "0",
                        BusGuideDateSecondPayment = bus.GuideSecondPayDate != null ? Convert.ToDateTime(bus.GuideSecondPayDate).ToString("dd/MMM/yyyy") : "",
                        BusGuideSelectedSecondPaymentMethod = bus.GuideSecondPayMethod,
                        BusGuideSecondPayment = bus.GuideSecondPayAmt != null ? Convert.ToDecimal(bus.GuideSecondPayAmt).ToString("F") : "0",
                        BusGuideDateThirdPayment = bus.GuideThirdPayDate != null ? Convert.ToDateTime(bus.GuideThirdPayDate).ToString("dd/MMM/yyyy") : "",
                        BusGuideSelectedThirdPaymentMethod = bus.GuideThirdPayMethod,
                        BusGuideThirdPayment = bus.GuideThirdPayAmt != null ? Convert.ToDecimal(bus.GuideThirdPayAmt).ToString("F") : "0",
                        BusConfHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='OperGroupBusConfLoad(" + bus.GroupID + "," + bus.VendorID + "," + "\"" + Convert.ToDateTime(bus.BusStartDate).ToString() + "\"" + "," + "\"" + "Bus" + "\"" + ")'>Details</button></div>",
                        BusGroupContractHtml = "<div style='text-align:center;'><button class='btn14 btn120 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationVendorContractDetails(" + "\"" + ContractGroupPath + "\"" + ")'>Vendor Contract</button></div>",
                        BusPayMeth1FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationBusAmexVendorDetails(" + bus.GroupID + "," + bus.VendorID + "," + 1 + "," + "\"" + Convert.ToDateTime(bus.BusStartDate).ToString() + "\"" + "," + "\"" + "Bus" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                        BusPayMeth2FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationBusAmexVendorDetails(" + bus.GroupID + "," + bus.VendorID + "," + 2 + "," + "\"" + Convert.ToDateTime(bus.BusStartDate).ToString() + "\"" + "," + "\"" + "Bus" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                        BusPayMeth3FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationBusAmexVendorDetails(" + bus.GroupID + "," + bus.VendorID + "," + 3 + "," + "\"" + Convert.ToDateTime(bus.BusStartDate).ToString() + "\"" + "," + "\"" + "Bus" + "\"" + "," + "\"" + "" + "\"" + ")'>Detail</button></div>",
                        GuidePayMeth1FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationBusAmexVendorDetails(" + bus.GroupID + "," + bus.GuideID + "," + 1 + "," + "\"" + Convert.ToDateTime(bus.BusStartDate).ToString() + "\"" + "," + "\"" + "Guide" + "\"" + "," + "\"" + "Guide" + "\"" + ")'>Detail</button></div>",
                        GuidePayMeth2FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationBusAmexVendorDetails(" + bus.GroupID + "," + bus.GuideID + "," + 2 + "," + "\"" + Convert.ToDateTime(bus.BusStartDate).ToString() + "\"" + "," + "\"" + "Guide" + "\"" + "," + "\"" + "Guide" + "\"" + ")'>Detail</button></div>",
                        GuidePayMeth3FormHtml = "<div style='text-align:center;'><button class='btn14 btn60 btnheight22' type='button' style='padding:0px;' onclick='ShowOperationBusAmexVendorDetails(" + bus.GroupID + "," + bus.GuideID + "," + 3 + "," + "\"" + Convert.ToDateTime(bus.BusStartDate).ToString() + "\"" + "," + "\"" + "Guide" + "\"" + "," + "\"" + "Guide" + "\"" + ")'>Detail</button></div>",
                    });
                    if (QuotaBusCurrency == "CAD")
                    {
                        CADBusTotalCostSum = CADBusTotalCostSum + BusTotalCost;
                        CADBusTotalPaidSum = CADBusTotalPaidSum + BusTotalPaid;
                        CADBusDifferenceSum = CADBusDifferenceSum + (BusDifference * Convert.ToInt32(bus.BusCount));
                    }
                    else if (QuotaBusCurrency == "USD")
                    {
                       BusTotalCostSum = BusTotalCostSum + BusTotalCost;
                       BusTotalPaidSum = BusTotalPaidSum + BusTotalPaid;
                       BusDifferenceSum = BusDifferenceSum + (BusDifference * Convert.ToInt32(bus.BusCount));
                    }
                    if (QuotaGuideCurrency == "CAD")
                    {
                        CADGuideTotalCostSum = CADGuideTotalCostSum + GuideTotalCost;
                        CADGuideTotalPaidSum = CADGuideTotalPaidSum + GuideTotalPaid;
                        CADGuideDifferenceSum = CADGuideDifferenceSum + GuideDifference;
                        CADGuideMiscDifferenceSum = CADGuideMiscDifferenceSum + GuideMiscDifference;
                        CADGuideStepOnDifferenceSum = CADGuideStepOnDifferenceSum + GuideStepOnDifference;
                    }
                    else if (QuotaGuideCurrency == "USD")
                    {
                        GuideTotalCostSum = GuideTotalCostSum + GuideTotalCost;
                        GuideTotalPaidSum = GuideTotalPaidSum + GuideTotalPaid;
                        GuideDifferenceSum = GuideDifferenceSum + GuideDifference;
                        GuideMiscDifferenceSum = GuideMiscDifferenceSum + GuideMiscDifference;
                        GuideStepOnDifferenceSum = GuideStepOnDifferenceSum + GuideStepOnDifference;
                    }
                }
            // Calc Group Profit
            if (BusData.SearchGroupCode != null)
            {
                OperBusGridView.BusTotCost = BusTotalCostSum + GuideTotalCostSum;
                OperBusGridView.BusTotCostCad = CADBusTotalCostSum + CADGuideTotalCostSum;
                OperBusGridView.BusGroupProfit = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='BusGroupProfit'></span><span class='OperationSumCAD GrpProfit' id='BusGroupProfitCad'></span></label>";
                OperBusGridView.BusTotInvoice = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='BusTotInv'></span><span class='OperationSumCAD GrpProfit' id='BusTotInvCAD'></span></label>";
                OperBusGridView.BusProfitPers = "<label class='form-control'><span class='OperationSumUSD GrpProfit' id='BusProfitPers'></span><span class='OperationSumCAD GrpProfit' id='BusProfitPersCAD'></span></label>";
            }
            // Bus Total
            OperBusGridView.BusTotalCostAmtSum = "<label class='form-control'>" + (BusTotalCostSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + BusTotalCostSum.ToString("F") + " USD" + (CADBusTotalCostSum == 0 ? "" : ",") + "</span>" + (CADBusTotalCostSum == 0 ? "" : (CADBusTotalCostSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADBusTotalCostSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperBusGridView.GuideTotalCostAmtSum = "<label class='form-control'>" + (GuideTotalCostSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + GuideTotalCostSum.ToString("F") + " USD" + (CADGuideTotalCostSum == 0 ? "" : ",") + "</span>" + (CADGuideTotalCostSum == 0 ? "" : (CADGuideTotalCostSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADGuideTotalCostSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperBusGridView.BusTotalPaidSum = "<label class='form-control'>" + (BusTotalPaidSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + BusTotalPaidSum.ToString("F") + " USD" + (CADBusTotalPaidSum == 0 ? "" : ",") + "</span>" + (CADBusTotalPaidSum == 0 ? "" : (CADBusTotalPaidSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADBusTotalPaidSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperBusGridView.GuideTotalPaidSum = "<label class='form-control'>" + (GuideTotalPaidSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + GuideTotalPaidSum.ToString("F") + " USD" + (CADGuideTotalPaidSum == 0 ? "" : ",") + "</span>" + (CADGuideTotalPaidSum == 0 ? "" : (CADGuideTotalPaidSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADGuideTotalPaidSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperBusGridView.BusDifferenceSum = "<label class='form-control'>" + (BusDifferenceSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + BusDifferenceSum.ToString("F") + " USD" + (CADBusDifferenceSum == 0 ? "" : ",") + "</span>" + (CADBusDifferenceSum == 0 ? "" : (CADBusDifferenceSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADBusDifferenceSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperBusGridView.GuideDifferenceSum = "<label class='form-control'>" + (GuideDifferenceSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + GuideDifferenceSum.ToString("F") + " USD" + (CADGuideDifferenceSum == 0 ? "" : ",") + "</span>" + (CADGuideDifferenceSum == 0 ? "" : (CADGuideDifferenceSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADGuideDifferenceSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperBusGridView.GuideTotalMiscDiffSum = "<label class='form-control'>" + (GuideMiscDifferenceSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + GuideMiscDifferenceSum.ToString("F") + " USD" + (CADGuideMiscDifferenceSum == 0 ? "" : ",") + "</span>" + (CADGuideMiscDifferenceSum == 0 ? "" : (CADGuideMiscDifferenceSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADGuideMiscDifferenceSum.ToString("F") + " CAD" + "</span>") + "</label>";
            OperBusGridView.GuideTotalStepOnSum = "<label class='form-control'>" + (GuideStepOnDifferenceSum < 0 ? "<span class='OperationSumUSD SumControls10Size'>" : "<span class='OperationSumUSD SumControls10Sizeblack'>") + GuideStepOnDifferenceSum.ToString("F") + " USD" + (CADGuideStepOnDifferenceSum == 0 ? "" : ",") + "</span>" + (CADGuideStepOnDifferenceSum == 0 ? "" : (CADGuideStepOnDifferenceSum < 0 ? "<span class='OperationSumCAD SumControls10Size'>" : "<span class='OperationSumCAD SumControls10Sizeblack'>") + CADGuideStepOnDifferenceSum.ToString("F") + " CAD" + "</span>") + "</label>";
            // Group Code filter
            OperBusGridView.BusFilterGroupCode = new List<CheckBoxControlViewModel>();
            OperBusGridView.BusFilterSelGroupCode = new List<CheckBoxControlViewModel>();
            // Group Name filter
            OperBusGridView.BusFilterGroupName = new List<CheckBoxControlViewModel>();
            OperBusGridView.BusFilterSelGroupName = new List<CheckBoxControlViewModel>();
            // Customer filter
            OperBusGridView.BusFilterCustomerCode = new List<CheckBoxControlViewModel>();
            OperBusGridView.BusFilterSelCustomerCode = new List<CheckBoxControlViewModel>();
            // Status filter
            OperBusGridView.BusFilterStatus = new List<CheckBoxControlViewModel>();
            OperBusGridView.BusFilterSelStatus = new List<CheckBoxControlViewModel>();
            // Vendor Name filter
            OperBusGridView.BusFilterVendorName = new List<CheckBoxControlViewModel>();
            OperBusGridView.BusFilterSelVendorName = new List<CheckBoxControlViewModel>();
            // Start City filter
            OperBusGridView.BusFilterStartCity = new List<CheckBoxControlViewModel>();
            OperBusGridView.BusFilterSelStartCity = new List<CheckBoxControlViewModel>();
            // End City filter
            OperBusGridView.BusFilterEndCity = new List<CheckBoxControlViewModel>();
            OperBusGridView.BusFilterSelEndCity = new List<CheckBoxControlViewModel>();
            // Group Code filter init
            if (BusData != null && BusData.FilterGroupCode != null)
                foreach (var grp in BusData.FilterGroupCode)
                {
                    OperBusGridView.BusFilterGroupCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Group Name filter init
            if (BusData != null && BusData.FilterGroupName != null)
                foreach (var grp in BusData.FilterGroupName)
                {
                    OperBusGridView.BusFilterGroupName.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Customer filter init
            if (BusData != null && BusData.FilterCustomerCode != null)
                foreach (var grp in BusData.FilterCustomerCode)
                {
                    OperBusGridView.BusFilterCustomerCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Status filter init
            if (BusData != null && BusData.FilterVendorStatus != null)
                foreach (var grp in BusData.FilterVendorStatus)
                {
                    OperBusGridView.BusFilterStatus.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Vendor Name filter init
            if (BusData != null && BusData.FilterVendorName != null)
                foreach (var grp in BusData.FilterVendorName)
                {
                    OperBusGridView.BusFilterVendorName.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Start City filter init
            if (BusData != null && BusData.FilterStartCity != null)
                foreach (var grp in BusData.FilterStartCity)
                {
                    OperBusGridView.BusFilterStartCity.Add(new CheckBoxControlViewModel { Id = grp, Name = grp });
                }
            // End City filter init
            if (BusData != null && BusData.FilterEndCity != null)
                foreach (var grp in BusData.FilterEndCity)
                {
                    OperBusGridView.BusFilterEndCity.Add(new CheckBoxControlViewModel { Id = grp, Name = grp });
                }
        }
        private void InitTechProgGridViewData(OperationTechProgGridBData TechProgData, OperationTechProgGridViewModel OperTechProgGridView)
        {
            OperTechProgGridView.TechProgErrorMessage = TechProgData.Error.Message;
            OperTechProgGridView.Rows = new List<OperationTechProgGridRowViewModel>(); 
            OperTechProgGridView.TechProgDetail = new List<System.Web.WebPages.Html.SelectListItem>();
            if (TechProgData != null)
            {
                OperTechProgGridView.TechProgGroupIDTxt = TechProgData.GroupID;
                OperTechProgGridView.TechProgUpdated = Convert.ToBoolean(TechProgData.TechUpdated);
                OperTechProgGridView.TechProgUpdtDate = Convert.ToDateTime(TechProgData.TechUpdateDate).ToString("dd/MMM/yy");
            }
            // init tech prog detail
            if (TechProgData != null && TechProgData.TechProgDetails != null)
                foreach (var detail in TechProgData.TechProgDetails)
                    OperTechProgGridView.TechProgDetail.Add(new System.Web.WebPages.Html.SelectListItem { Text = detail.Value, Value = detail.Key.ToString() });

            if (TechProgData != null && TechProgData.Rows != null)
                foreach (var tech in TechProgData.Rows)
                {
                    OperTechProgGridView.Rows.Add(new OperationTechProgGridRowViewModel()
                    {
                        TechProgGroupID = tech.GroupID,
                        TechProgVendorAddress = tech.VendorAddress,
                        TechProgVendorEmail = tech.VendorEmail,
                        TechProgGuidePhone = tech.GuidePhone,
                        TechProgDetail = tech.Detail,
                        TechProgGuide = tech.Guide,
                        TechProgVendor = tech.Vendor,
                        TechProgEmployee = tech.Employee,
                        TechProgDay = ((tech.Date - TechProgData.GroupArrivalDate).Days + 1).ToString(),
                        TechProgDate = tech.Date.ToString("ddd, dd/MMM/yy"),
                        TechProgTime = tech.Time.ToString(@"hh\:mm"),
                        TechProgOldTime = tech.Time.ToString(@"hh\:mm"),
                        TechProgDesc = tech.Desc,
                        TechProgVia = tech.Via,
                        TechProgCity = tech.City,
                        TechProgArea = tech.Area,
                        TechProgType = tech.Type,
                        TechProgPrnFlag = Convert.ToBoolean(tech.PrnFlag),
                    });
                }
            // Type filter
            OperTechProgGridView.TechProgFilterType = new List<CheckBoxControlViewModel>();
            OperTechProgGridView.TechProgFilterSelType = new List<CheckBoxControlViewModel>();

            // Type filter init
            if (TechProgData != null && TechProgData.FilterTechProgType != null)
                foreach (var type in TechProgData.FilterTechProgType)
                {
                    OperTechProgGridView.TechProgFilterType.Add(new CheckBoxControlViewModel { Id = type, Name = type });
                }

        }
        private void InitGroupCheckListGridViewData(OperationGroupCheckListGridBData GroupCheckListData, OperationGroupCheckListGridViewModel OperGroupCheckListGridView)
        {
            OperGroupCheckListGridView.Rows = new List<OperationGroupCheckListGridRowViewModel>();
            if (GroupCheckListData != null && GroupCheckListData.Rows != null)
                foreach (var grpchek in GroupCheckListData.Rows)
                {
                    OperGroupCheckListGridView.Rows.Add(new OperationGroupCheckListGridRowViewModel()
                    {
                        GroupCheckListGroupCode = grpchek.GroupCode,
                        GroupCheckListGroupName = grpchek.GroupName,
                        GroupCheckListArrivalCity = grpchek.ArrivalCity,
                        GroupCheckListArrivalDate = grpchek.ArrivalDate != null ? Convert.ToDateTime(grpchek.ArrivalDate).ToString("ddd, dd/MMM/yy") : "",
                        GroupCheckListDepartureCity = grpchek.DepartureCity,
                        GroupCheckListDepartureDate = grpchek.DepartureDate != null ? Convert.ToDateTime(grpchek.DepartureDate).ToString("ddd, dd/MMM/yy") : "",
                        GroupCheckListCustomer = grpchek.Customer,
                        GroupCheckListPax = grpchek.NumOfPerson.ToString(),
                        GroupCheckListIsGir = grpchek.IsGir == true ? "Yes" : "No",
                        GroupCheckListMonthOfArrival = grpchek.ArrivalDate != null ? Convert.ToDateTime(grpchek.ArrivalDate).ToString("MMMM") : "",
                        GroupCheckListHotelStatus = grpchek.HotelStatus,
                        GroupCheckListHotelNotes = grpchek.HotelNotes,
                        GroupCheckListBusGuideNotes = grpchek.BusGuideNotes,
                    });
                }
            // Search Parametrs init
            Dictionary<bool, string> IsGir = new Dictionary<bool, string>() { { true, "Yes" }, { false, "No" } };
            OperGroupCheckListGridView.IsGir = new List<System.Web.WebPages.Html.SelectListItem>();
            // gir init
            foreach (var gir in IsGir)
            {
                OperGroupCheckListGridView.IsGir.Add(new System.Web.WebPages.Html.SelectListItem { Text = gir.Value, Value = gir.Key.ToString() });
            }
            // Group Code filter
            OperGroupCheckListGridView.GroupCheckListFilterGroupCode = new List<CheckBoxControlViewModel>();
            OperGroupCheckListGridView.GroupCheckListFilterSelGroupCode = new List<CheckBoxControlViewModel>();
            // Group Name filter
            OperGroupCheckListGridView.GroupCheckListFilterGroupName = new List<CheckBoxControlViewModel>();
            OperGroupCheckListGridView.GroupCheckListFilterSelGroupName = new List<CheckBoxControlViewModel>();
            // Customer filter
            OperGroupCheckListGridView.GroupCheckListFilterCustomerCode = new List<CheckBoxControlViewModel>();
            OperGroupCheckListGridView.GroupCheckListFilterSelCustomerCode = new List<CheckBoxControlViewModel>();
            // Group Code filter init
            if (GroupCheckListData != null && GroupCheckListData.FilterGroupCode != null)
                foreach (var grp in GroupCheckListData.FilterGroupCode)
                {
                    OperGroupCheckListGridView.GroupCheckListFilterGroupCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Group Name filter init
            if (GroupCheckListData != null && GroupCheckListData.FilterGroupName != null)
                foreach (var grp in GroupCheckListData.FilterGroupName)
                {
                    OperGroupCheckListGridView.GroupCheckListFilterGroupName.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
            // Customer filter init
            if (GroupCheckListData != null && GroupCheckListData.FilterCustomerCode != null)
                foreach (var grp in GroupCheckListData.FilterCustomerCode)
                {
                    OperGroupCheckListGridView.GroupCheckListFilterCustomerCode.Add(new CheckBoxControlViewModel { Id = grp.Key.ToString(), Name = grp.Value });
                }
        }
        private OperationVHotelGridViewModel InitOperVHotelGridViewModel(OperationVendorHotelGridBData data)
        {
            OperationVHotelGridViewModel VHotelViewModel = new OperationVHotelGridViewModel();
            VHotelViewModel.VHotelStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            VHotelViewModel.Rows = new List<OperationVHotelGridRowViewModel>();
            if(data != null && data.Status != null)
                foreach (var st in data.Status)
                    VHotelViewModel.VHotelStatus.Add(new System.Web.WebPages.Html.SelectListItem { Text = st.Value, Value = st.Key.ToString() });
            if (data != null && data.Rows != null)
                foreach (var row in data.Rows)
                    VHotelViewModel.Rows.Add(new OperationVHotelGridRowViewModel
                    {
                        VHotelArrivalDate = row.ArrivalDate.ToString("ddd, dd/MMM/yy"),
                        VHotelDepartureDate = row.DepartureDate != null? Convert.ToDateTime(row.DepartureDate).ToString("ddd, dd/MMM/yy"):"",
                        VHotelStatus = row.StatusSel,
                        VHotelStatusID = row.Status.ToString(),
                        VHotelVendorName = row.VendorName,
                        VendorId = row.VendorId,
                        VHotelPreviewHtml = "<div style='text-align:center;'><button class='btn14  btn60 btnheight22' type='button' style='padding:0px;' onclick='OperVendorHotelPrev(" + row.VendorId + "," + "\"" + row.ArrivalDate.ToString() + "\"" + ")'>Preview</button></div>",
                        VHotelOverwriteHtml = "<div style='text-align:center;'><button class='btn14  btn60 btnheight22' type='button' style='padding:0px;' onclick='RoomGridOverwrite(" + row.VendorId + "," + "\"" + row.ArrivalDate.ToString() + "\"" + ")''>Overwrite</button></div>",
                        VHotelVConfHtml = "<div style='text-align:center;'><button class='btn14  btn50 btnheight22' type='button' style='padding:0px;' onclick='OperGroupVendorLoad(" + row.VendorId + "," + "\"" + row.ArrivalDate.ToString() + "\"" + ")'>-></button></div>",
                    });
            return VHotelViewModel;
        }
        private OperationGroupVendorGridViewModel InitOperGroupVendorGridViewModel(OperationGVendorRoomGridBData data)
        {
            OperationGroupVendorGridViewModel GVendorViewModel = new OperationGroupVendorGridViewModel();
            GVendorViewModel.GVendorRoomTitle = new List<System.Web.WebPages.Html.SelectListItem>();
            GVendorViewModel.GVendorRoomType = new List<System.Web.WebPages.Html.SelectListItem>();
            GVendorViewModel.GVendorRoomTitleSingle = new List<System.Web.WebPages.Html.SelectListItem>();
            GVendorViewModel.GVendorRoomTitleDouble = new List<System.Web.WebPages.Html.SelectListItem>();
            GVendorViewModel.GVendorRoomTitleTwin = new List<System.Web.WebPages.Html.SelectListItem>();
            GVendorViewModel.GVendorRoomTitleTriple = new List<System.Web.WebPages.Html.SelectListItem>();
            GVendorViewModel.GVendorRoomTitleQuad = new List<System.Web.WebPages.Html.SelectListItem>();
            GVendorViewModel.GVendorRoomTitleDriver = new List<System.Web.WebPages.Html.SelectListItem>();
            GVendorViewModel.GVendorRoomTitleGuide = new List<System.Web.WebPages.Html.SelectListItem>();

            GVendorViewModel.GVendorVendorName = data.VendorName;
            GVendorViewModel.PorterageNotes = data.PorterageNotes;
            GVendorViewModel.RoomListNotes = data.RoomListNotes;
            GVendorViewModel.RoomListEditNotes = data.RoomListEditNotes;
            GVendorViewModel.PorterageFlag = data.PorterageFlag == true ? true : false;

            GVendorViewModel.Rows = new List<OperationGroupVendorGridRowViewModel>();
            GVendorViewModel.GVendorRoomTitles = data.Title.Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
            foreach (var type in data.Roomtype)
            {
                GVendorViewModel.GVendorRoomType.Add(new System.Web.WebPages.Html.SelectListItem() { Text = type.Value, Value = type.Key.ToString() });
                
                switch (type.Value)
                {
                    case "Single":
                        GVendorViewModel.GVendorRoomTitleSingle = data.Title.Where(ttl => ttl.ServiceCode == "Single").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                        break;
                    case "Double":
                        GVendorViewModel.GVendorRoomTitleDouble = data.Title.Where(ttl => ttl.ServiceCode == "Double").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                        break;
                    case "Twin":
                        GVendorViewModel.GVendorRoomTitleTwin = data.Title.Where(ttl => ttl.ServiceCode == "Twin").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                        break;
                    case "Triple":
                        GVendorViewModel.GVendorRoomTitleTriple = data.Title.Where(ttl => ttl.ServiceCode == "Triple").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                        break;
                    case "Quad":
                        GVendorViewModel.GVendorRoomTitleQuad = data.Title.Where(ttl => ttl.ServiceCode == "Quad").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                        break;
                    case "Driver":
                        GVendorViewModel.GVendorRoomTitleDriver = data.Title.Where(ttl => ttl.ServiceCode == "Driver").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                        break;
                    case "Guide":
                        GVendorViewModel.GVendorRoomTitleGuide = data.Title.Where(ttl => ttl.ServiceCode == "Guide").Select(ttl => new System.Web.WebPages.Html.SelectListItem() { Text = ttl.Title, Value = ttl.Title }).ToList();
                        break;
                }
            }
            int Room = 0;
            int Pax = 0;
            foreach (var row in data.Rows)
            {
                Room++;
                Pax += row.NumOfPerson;
                GVendorViewModel.Rows.Add(new OperationGroupVendorGridRowViewModel
                {
                    GVendorDeleteHtml = "<button class='btn btn-danger' type='button' style='padding:0px;' onclick='RemoveGroupVendorRoomByLine(" + row.GroupID + "," + row.VendorID + "," + row.LineNo + ")'>Delete</button>",
                    GVendorGroupID = row.GroupID,
                    GVendorLineNo = row.LineNo.ToString(),
                    GVendorNames = row.Names,
                    GVendorNoOfPerson = row.NumOfPerson.ToString(),
                    GVendorNotes = row.Notes,
                    RoomType = data.Roomtype.Where(rm => rm.Key == row.ServiceID).SingleOrDefault().Value,
                    GVendorSelectedRoomTitle = row.Title,
                    GVendorSelectedRoomType = row.SelService,
                    GVendorSelectedRoomTypeID = row.ServiceID.ToString(),
                    GVendorVendorID = row.VendorID,
                    GVendorArrivalDate = row.ArrivalDate != null ? Convert.ToDateTime(row.ArrivalDate).ToString("ddd, dd/MMM/yy") : null,
                    GVendorDepartureDate = row.DepartureDate != null ? Convert.ToDateTime(row.DepartureDate).ToString("ddd, dd/MMM/yy") : null,
                });
            }
            var RoomsByType = GVendorViewModel.Rows.GroupBy(row => row.RoomType).Select(row => new { Roomtype = row.Key, RoomCount = row.Count() }).ToList();
            GVendorViewModel.TotalSgl = RoomsByType.Any(room => room.Roomtype == "Single") ? RoomsByType.Where(room => room.Roomtype == "Single").SingleOrDefault().RoomCount.ToString() : "0";
            GVendorViewModel.TotalDbl = RoomsByType.Any(room => room.Roomtype == "Double") ? RoomsByType.Where(room => room.Roomtype == "Double").SingleOrDefault().RoomCount.ToString() : "0";
            GVendorViewModel.TotalTwn = RoomsByType.Any(room => room.Roomtype == "Twin") ? RoomsByType.Where(room => room.Roomtype == "Twin").SingleOrDefault().RoomCount.ToString() : "0";
            GVendorViewModel.TotalTrpl = RoomsByType.Any(room => room.Roomtype == "Triple") ? RoomsByType.Where(room => room.Roomtype == "Triple").SingleOrDefault().RoomCount.ToString() : "0";
            GVendorViewModel.TotalQud = RoomsByType.Any(room => room.Roomtype == "Quad") ? RoomsByType.Where(room => room.Roomtype == "Quad").SingleOrDefault().RoomCount.ToString() : "0";
            GVendorViewModel.TotalDriver = RoomsByType.Any(room => room.Roomtype == "Driver") ? RoomsByType.Where(room => room.Roomtype == "Driver").SingleOrDefault().RoomCount.ToString() : "0";
            GVendorViewModel.TotalGuide = RoomsByType.Any(room => room.Roomtype == "Guide") ? RoomsByType.Where(room => room.Roomtype == "Guide").SingleOrDefault().RoomCount.ToString() : "0";
            GVendorViewModel.TotalRooms = Room.ToString();
            GVendorViewModel.TotalPax = Pax.ToString();
            return GVendorViewModel;
        }
        private OperationGVendorRoomGridBData InitOperationGVendorRoomGridBData(OperationGroupVendorGridViewModel model)
        {
            OperationGVendorRoomGridBData Data = new OperationGVendorRoomGridBData();
            Data.GroupID = model.GVendorGroupID;
            Data.VendorID = model.GVendorVendorID;
            Data.ArrivalDate = Convert.ToDateTime(model.GVendorArrivalDate);
            Data.PorterageNotes = model.PorterageNotes;
            Data.RoomListNotes = model.RoomListNotes;
            Data.RoomListEditNotes = model.RoomListEditNotes;
            Data.PorterageFlag = model.PorterageFlag;
            Data.Rows = new List<OperationGVendorRoomGridRowBData>();
            foreach (var row in model.Rows)
                Data.Rows.Add(new OperationGVendorRoomGridRowBData
                {
                    GroupID = Convert.ToInt32(row.GVendorGroupID),
                    VendorID = Convert.ToInt32(row.GVendorVendorID),
                    ServiceID = Convert.ToInt32(row.GVendorSelectedRoomTypeID),
                    Title = row.GVendorSelectedRoomTitle,
                    Names = row.GVendorNames,
                    Notes = row.GVendorNotes,
                    LineNo = Convert.ToInt32(row.GVendorLineNo),
                    ArrivalDate = row.GVendorArrivalDate != null ? Convert.ToDateTime(row.GVendorArrivalDate):(DateTime?)null,
                    DepartureDate = row.GVendorDepartureDate != null ? Convert.ToDateTime(row.GVendorDepartureDate) : (DateTime?)null,
                });
            return Data;
        }
        private OperationAttrBusConfirmationViewModel InitOperAttrBusConfirmationGridViewModel(OperationAttrBusConfirmGridBData data, string VendorType)
        {
            OperationAttrBusConfirmationViewModel AttrBusConfVModel = new OperationAttrBusConfirmationViewModel();
            AttrBusConfVModel.AttrBusConfStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            AttrBusConfVModel.AttrBusConfService = new List<System.Web.WebPages.Html.SelectListItem>();
            AttrBusConfVModel.AttrBusConfArrivalDate = data.ArrivalDate.ToString("dd/MMM/yy");
            AttrBusConfVModel.AttrBusConfVendorName = data.VendorName;
            AttrBusConfVModel.AttrBusConfArrivalTime = data.ArrivalTime != null ? Convert.ToDateTime(data.ArrivalTime).ToString("HH:mm") : "";
            AttrBusConfVModel.AttrBusConfSelectedStatus = data.StatusID.ToString();
            AttrBusConfVModel.AttrBusConfEmployee = data.Employee;
            AttrBusConfVModel.AttrBusConfEmployeeId = Convert.ToInt32(data.EmployeeId);
            AttrBusConfVModel.AttrBusConfNote = data.Note;
            AttrBusConfVModel.AttrBusConfGroupID = data.GroupID;
            AttrBusConfVModel.AttrBusConfGroupCode = data.GroupCode;
            AttrBusConfVModel.AttrBusConfVendorID = data.VendorID;
            AttrBusConfVModel.AttrBusConfirmFile = data.VendorConfirmFile != null ? (System.IO.File.Exists(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["UploadVendorConfirmContract"]) + data.VendorConfirmFile) ? data.VendorConfirmFile : null) : null;
            AttrBusConfVModel.AttrBusVendorType = VendorType;

            foreach (var st in data.Status)
                AttrBusConfVModel.AttrBusConfStatus.Add(new System.Web.WebPages.Html.SelectListItem { Text = st.Value, Value = st.Key.ToString() });
            foreach (var serv in data.Service)
                AttrBusConfVModel.AttrBusConfService.Add(new System.Web.WebPages.Html.SelectListItem { Text = serv.Value, Value = serv.Key.ToString() });

            return AttrBusConfVModel;
        }
        private OperationVendorConfirmationViewModel InitOperVendorConfirmationGridViewModel(OperationVendorConfirmGridBData data)
        {
            OperationVendorConfirmationViewModel VConfVModel = new OperationVendorConfirmationViewModel();
            VConfVModel.Rows = new List<OperationVendorConfirmationGridViewModel>();
            VConfVModel.RoomRows = new List<OperationVendorConfirmationRoomsGridViewModel>();
            VConfVModel.MealRows = new List<OperationVendorConfirmationMealsGridViewModel>();
            VConfVModel.ConfStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            VConfVModel.ConfService= new List<System.Web.WebPages.Html.SelectListItem>();
            VConfVModel.ConfArrivalDate = data.ArrivalDate.ToString("dd/MMM/yy");
            VConfVModel.ConfVendorName = data.VendorName;
            VConfVModel.ConfArrivalTime = data.ArrivalTime != null? Convert.ToDateTime(data.ArrivalTime).ToString("HH:mm"):"";
            VConfVModel.ConfDepartureDate = data.DepartureDate != null? Convert.ToDateTime(data.DepartureDate).ToString("dd/MMM/yy"):"";
            VConfVModel.ConfDepartureTime = data.DepartureTime != null ? Convert.ToDateTime(data.DepartureTime).ToString("HH:mm") : "";
            VConfVModel.ConfVoucher = data.Voucher == null ? false : Convert.ToBoolean(data.Voucher);
            VConfVModel.ConfSelectedStatus = data.StatusID.ToString();
            VConfVModel.ConfConfirmedBy = data.ConfirmedBy;
            VConfVModel.ConfConfirmDate = data.ConfirmDate != null ? Convert.ToDateTime(data.ConfirmDate).ToString("dd/MMM/yy") : "";
            VConfVModel.ConfTourLeader = data.TourLeader;
            VConfVModel.ConfEmployee = data.Employee;
            VConfVModel.ConfEmployeeId = Convert.ToInt32(data.EmployeeId);
            VConfVModel.ConfIssueDate = data.IssueDate != null ? Convert.ToDateTime(data.IssueDate).ToString("dd/MMM/yy") : "";
            VConfVModel.ConfRooms = data.Rooms != null ? Convert.ToInt32(data.Rooms).ToString() : "";
            VConfVModel.ConfPax = data.Pax != null ? Convert.ToInt16(data.Pax).ToString() : "";
            VConfVModel.ConfPaxPlus = data.PaxPlus != null ? Convert.ToInt16(data.PaxPlus).ToString() : "";
            VConfVModel.ConfNote = data.Note;
            VConfVModel.ConfLuggage = data.Luggage != null ? Convert.ToDecimal(data.Luggage).ToString("F") : "";
            VConfVModel.ConfTax = data.Tax != null ? Convert.ToDouble(data.Tax).ToString("F") : "";
            VConfVModel.ConfOccTax = data.OccTax != null ? Convert.ToDecimal(data.OccTax).ToString("F") : "";
            VConfVModel.ConfGratuity = data.Gratuity != null ? Convert.ToDouble(data.Gratuity).ToString("F") : "";
            VConfVModel.ConfGroupID = data.GroupID;
            VConfVModel.ConfGroupCode = data.GroupCode;
            VConfVModel.ConfVendorID = data.VendorID;
            VConfVModel.VendorConfirmFile = data.VendorConfirmFile != null ? (System.IO.File.Exists(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["UploadVendorConfirmContract"]) + data.VendorConfirmFile) ? data.VendorConfirmFile : null) : null;
            VConfVModel.VendorType = "Hotel";

            foreach(var st in data.Status)
                VConfVModel.ConfStatus.Add(new System.Web.WebPages.Html.SelectListItem { Text = st.Value, Value = st.Key.ToString() });
            foreach (var serv in data.Service)
                VConfVModel.ConfService.Add(new System.Web.WebPages.Html.SelectListItem { Text = serv.Value, Value = serv.Key.ToString() });
            int RoomDay = 1;
            int MealDay = 1;

            foreach (var row in data.Rows)
            {
                if(row.IsRow == true)
                {
                    VConfVModel.Rows.Add(new OperationVendorConfirmationGridViewModel
                    {
                        ConfStartDate = row.StartDate != null ? Convert.ToDateTime(row.StartDate).ToString("ddd, dd/MMM/yy") : "",
                        ConfEndDate = row.EndDate != null ? Convert.ToDateTime(row.EndDate).ToString("ddd, dd/MMM/yy") : "",
                        ConfLineNo = row.LineNo.ToString(),
                        ConfPrice = row.Price != null ? Convert.ToDecimal(row.Price).ToString("F") : "",
                        ConfXQty = row.XQty != null ? Convert.ToInt16(row.XQty).ToString() : "",
                        ConfQty = row.Qty != null ? Convert.ToInt16(row.Qty).ToString() : "",
                        ConfDescription = row.Description,
                        ConfSelServiceID = row.SelServiceID.ToString(),
                        ConfSelService = row.SelService,
                    });
                }
                else
                { 
                    if (VConfVModel.RoomRows.Any(Rrow => Rrow.StartDate == row.StartDate && Rrow.EndDate == row.EndDate))
                    {
                        var RoomR = VConfVModel.RoomRows.Where(Rrow => Rrow.StartDate == row.StartDate && Rrow.EndDate == row.EndDate).FirstOrDefault();
                        UpdateServiceVendConf(row, ref RoomR);
                    }
                    else if (row.VendorTypeID == 1 && row.SelService.Contains("Room"))
                    {
                        OperationVendorConfirmationRoomsGridViewModel RoomR = new OperationVendorConfirmationRoomsGridViewModel
                        {
                            ConfRoomDay = RoomDay.ToString(),
                            StartDate = row.StartDate,
                            EndDate = row.EndDate,
                        };
                        UpdateServiceVendConf(row, ref RoomR);
                        VConfVModel.RoomRows.Add(RoomR);
                        RoomDay++;
                    }
                    if (VConfVModel.MealRows.Any(Mrow => Mrow.MealStartDate == row.StartDate && Mrow.MealEndDate == row.EndDate))
                    {
                        var MealR = VConfVModel.MealRows.Where(Mrow => Mrow.MealStartDate == row.StartDate && Mrow.MealEndDate == row.EndDate).FirstOrDefault();
                        UpdateServiceVendConf(row, ref MealR);
                    }
                    else if (row.VendorTypeID == 1 && (row.SelService.Contains("Breakfast") || row.SelService.Contains("Lunch") || row.SelService.Contains("Dinner")))
                    {
                        OperationVendorConfirmationMealsGridViewModel MealR = new OperationVendorConfirmationMealsGridViewModel
                        {
                            ConfMealDay = MealDay.ToString(),
                            MealStartDate = row.StartDate,
                            MealEndDate = row.EndDate,
                            StartDate = Convert.ToDateTime(row.StartDate).ToString("ddd, dd/MMM/yy"),
                        };
                        UpdateServiceVendConf(row, ref MealR);
                        VConfVModel.MealRows.Add(MealR);
                        MealDay++;
                    }
                }
            }
            return VConfVModel;
        }
        private void UpdateServiceVendConf(OperationVendorConfirmGridRowBData row, ref OperationVendorConfirmationRoomsGridViewModel RoomR)
        {
            if (row.SelService.Contains("Room"))
            {
                if (row.SelService.Contains("Single"))
                {
                    RoomR.ConfRoomSingleQty = row.Qty.ToString();
                    RoomR.ConfRoomSinglePrice = row.Price.ToString();
                }
                if (row.SelService.Contains("Double"))
                {
                    RoomR.ConfRoomDoubleQty = row.Qty.ToString();
                    RoomR.ConfRoomDoublePrice = row.Price.ToString();
                }
                if (row.SelService.Contains("Twin"))
                {
                    RoomR.ConfRoomTwinQty = row.Qty.ToString();
                    RoomR.ConfRoomTwinPrice = row.Price.ToString();
                }
                if (row.SelService.Contains("Triple"))
                {
                    RoomR.ConfRoomTripleQty = row.Qty.ToString();
                    RoomR.ConfRoomTriplePrice = row.Price.ToString();
                }
                if (row.SelService.Contains("Quad"))
                {
                    RoomR.ConfRoomQuadQty = row.Qty.ToString();
                    RoomR.ConfRoomQuadPrice = row.Price.ToString();
                }
                if (row.SelService.Contains("Driver"))
                {
                    RoomR.ConfRoomDriverQty = row.Qty.ToString();
                    RoomR.ConfRoomDriverPrice = row.Price.ToString();
                }
                if (row.SelService.Contains("Guide"))
                {
                    RoomR.ConfRoomGuideQty = row.Qty.ToString();
                    RoomR.ConfRoomGuidePrice = row.Price.ToString();
                }
                if (row.SelService.Contains("Baggage"))
                {
                    RoomR.ConfRoomBaggageQty = row.Qty.ToString();
                    RoomR.ConfRoomBaggagePrice = row.Price.ToString();
                }
            }
        }
        private void UpdateServiceVendConf(OperationVendorConfirmGridRowBData row, ref OperationVendorConfirmationMealsGridViewModel MealR)
        {
            if (row.SelService.Contains("Breakfast"))
            {
                if (row.SelService.Contains("American"))
                {
                    MealR.ConfMealABFQty = row.Qty.ToString();
                    MealR.ConfMealABFPrice = row.Price.ToString();
                    MealR.ConfMealABFCheck = Convert.ToBoolean(row.Product);
                }
                if (row.SelService.Contains("Continental"))
                {
                    MealR.ConfMealCBFQty = row.Qty.ToString();
                    MealR.ConfMealCBFPrice = row.Price.ToString();
                    MealR.ConfMealCBFCheck = Convert.ToBoolean(row.Product);
                }
            }
            if (row.SelService.Contains("Lunch"))
            {
                MealR.ConfMealLunchQty = row.Qty.ToString();
                MealR.ConfMealLunchPrice = row.Price.ToString();
                MealR.ConfMealLunchCheck = Convert.ToBoolean(row.Product);
            }
            if (row.SelService.Contains("Dinner"))
            {
                MealR.ConfMealDinnerQty = row.Qty.ToString();
                MealR.ConfMealDinnerPrice = row.Price.ToString();
                MealR.ConfMealDinnerCheck = Convert.ToBoolean(row.Product);
            }
        }
        private OperationVendorConfirmGridBData InitOperationVendorConfirmGridBData(OperationVendorConfirmationViewModel model)
        {
            OperationVendorConfirmGridBData ConfBData = new OperationVendorConfirmGridBData();
            ConfBData.ArrivalDate = Convert.ToDateTime(model.ConfArrivalDate);
            ConfBData.ArrivalTime = model.ConfArrivalTime != null ? Convert.ToDateTime(model.ConfArrivalTime) : (DateTime?)null;
            ConfBData.DepartureDate = model.ConfDepartureDate != null ? Convert.ToDateTime(model.ConfDepartureDate) : (DateTime?)null;
            ConfBData.DepartureTime = model.ConfDepartureTime != null ? Convert.ToDateTime(model.ConfDepartureTime) : (DateTime?)null;
            ConfBData.StatusID = model.ConfSelectedStatus != null ? Convert.ToInt32(model.ConfSelectedStatus) : (int?)null;
            ConfBData.GroupID = model.ConfGroupID;
            ConfBData.VendorID = model.ConfVendorID;
            ConfBData.ConfirmedBy = model.ConfConfirmedBy;
            ConfBData.ConfirmDate = model.ConfConfirmDate != null ? Convert.ToDateTime(model.ConfConfirmDate) : (DateTime?)null;
            ConfBData.Note = model.ConfNote;
            ConfBData.IssueDate = model.ConfIssueDate != null ? Convert.ToDateTime(model.ConfIssueDate) : (DateTime?)null;
            ConfBData.Rooms = model.ConfRooms != null ? Convert.ToDouble(model.ConfRooms) : (double?)null;
            ConfBData.Pax = model.ConfPax != null ? Convert.ToInt16(model.ConfPax) : (short?)null;
            ConfBData.Luggage = model.ConfLuggage != null ? Convert.ToDecimal(model.ConfLuggage) : (decimal?)null;
            ConfBData.Tax = model.ConfTax != null ? Convert.ToDouble(model.ConfTax) : (double?)null;
            ConfBData.OccTax = model.ConfOccTax != null ? Convert.ToDecimal(model.ConfOccTax) : (decimal?)null;
            ConfBData.Rows = new List<OperationVendorConfirmGridRowBData>();
            int lineNo = 1;
            if (model.Rows != null)
            foreach(var row in model.Rows)
            {
                if (row.ConfSelServiceID != null)
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    LineNo = Convert.ToInt32(row.ConfLineNo),
                    Description = row.ConfDescription,
                    StartDate = row.ConfStartDate != null ? Convert.ToDateTime(row.ConfStartDate) : (DateTime?)null,
                    EndDate = row.ConfEndDate != null ? Convert.ToDateTime(row.ConfEndDate) : (DateTime?)null,
                    Price = row.ConfPrice != null ? Convert.ToDecimal(row.ConfPrice) : (decimal?)null,
                    Qty = row.ConfQty != null ? Convert.ToInt16(row.ConfQty) : (short?)null,
                    XQty = row.ConfXQty != null ? Convert.ToInt16(row.ConfXQty) : (short?)null,
                    SelServiceID = row.ConfSelServiceID != null ? Convert.ToInt32(row.ConfSelServiceID) : (int?)null,
                    IsRow = true,
                });
            }
            int Day = 0;
            int MealDay = 0;
            if (model.RoomRows != null)
            foreach (var Rmrow in model.RoomRows)
            {
                Day++;
                // Single Room
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day-1),
                    EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day),
                    Price = Convert.ToDecimal(Rmrow.ConfRoomSinglePrice),
                    Qty = Convert.ToInt16(Rmrow.ConfRoomSingleQty),
                    Description = "Single",
                });
                // Double Room
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day - 1),
                    EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day),
                    Price = Convert.ToDecimal(Rmrow.ConfRoomDoublePrice),
                    Qty = Convert.ToInt16(Rmrow.ConfRoomDoubleQty),
                    Description = "Double",
                });
                // Twin Room
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day - 1),
                    EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day),
                    Price = Convert.ToDecimal(Rmrow.ConfRoomTwinPrice),
                    Qty = Convert.ToInt16(Rmrow.ConfRoomTwinQty),
                    Description = "Twin",
                });
                // Triple Room
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day - 1),
                    EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day),
                    Price = Convert.ToDecimal(Rmrow.ConfRoomTriplePrice),
                    Qty = Convert.ToInt16(Rmrow.ConfRoomTripleQty),
                    Description = "Triple",
                });
                // Quad Room
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day - 1),
                    EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day),
                    Price = Convert.ToDecimal(Rmrow.ConfRoomQuadPrice),
                    Qty = Convert.ToInt16(Rmrow.ConfRoomQuadQty),
                    Description = "Quad",
                });
                // Driver Room
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day - 1),
                    EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day),
                    Price = Convert.ToDecimal(Rmrow.ConfRoomDriverPrice),
                    Qty = Convert.ToInt16(Rmrow.ConfRoomDriverQty),
                    Description = "Driver",
                });
                // Guide Room
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day - 1),
                    EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day),
                    Price = Convert.ToDecimal(Rmrow.ConfRoomGuidePrice),
                    Qty = Convert.ToInt16(Rmrow.ConfRoomGuideQty),
                    Description = "Guide",
                });
                // Baggage 
                ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                {
                    StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day - 1),
                    EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(Day),
                    Price = Convert.ToDecimal(Rmrow.ConfRoomBaggagePrice),
                    Qty = Convert.ToInt16(Rmrow.ConfRoomBaggageQty),
                    Description = "Baggage",
                });
            }
            if (model.MealRows != null)
                foreach (var Mrow in model.MealRows)
                {
                    MealDay++;
                    // ABF 
                    ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                    {
                        StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(MealDay - 1),
                        EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(MealDay),
                        Price = Convert.ToDecimal(Mrow.ConfMealABFPrice),
                        Qty = Convert.ToInt16(Mrow.ConfMealABFQty),
                        Product = Convert.ToInt32(Mrow.ConfMealABFCheck),
                        Description = "ABF",
                    });
                    // CBF 
                    ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                    {
                        StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(MealDay - 1),
                        EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(MealDay),
                        Price = Convert.ToDecimal(Mrow.ConfMealCBFPrice),
                        Qty = Convert.ToInt16(Mrow.ConfMealCBFQty),
                        Product = Convert.ToInt32(Mrow.ConfMealCBFCheck),
                        Description = "CBF",
                    });
                    // Lunch 
                    ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                    {
                        StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(MealDay - 1),
                        EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(MealDay),
                        Price = Convert.ToDecimal(Mrow.ConfMealLunchPrice),
                        Qty = Convert.ToInt16(Mrow.ConfMealLunchQty),
                        Product = Convert.ToInt32(Mrow.ConfMealLunchCheck),
                        Description = "Lunch",
                    });
                    // Dinner 
                    ConfBData.Rows.Add(new OperationVendorConfirmGridRowBData
                    {
                        StartDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(MealDay - 1),
                        EndDate = Convert.ToDateTime(model.ConfArrivalDate).AddDays(MealDay),
                        Price = Convert.ToDecimal(Mrow.ConfMealDinnerPrice),
                        Qty = Convert.ToInt16(Mrow.ConfMealDinnerQty),
                        Product = Convert.ToInt32(Mrow.ConfMealDinnerCheck),
                        Description = "Dinner",
                    });
                }
            return ConfBData;
        }
        private OperationAttrBusConfirmGridBData InitOperationAttrBusConfirmGridBData(OperationAttrBusConfirmationViewModel model)
        {
            OperationAttrBusConfirmGridBData ConfBData = new OperationAttrBusConfirmGridBData();
            ConfBData.ArrivalDate = Convert.ToDateTime(model.AttrBusConfArrivalDate);
            ConfBData.ArrivalTime = model.AttrBusConfArrivalTime != null ? Convert.ToDateTime(model.AttrBusConfArrivalTime) : (DateTime?)null;
            ConfBData.StatusID = model.AttrBusConfSelectedStatus != null ? Convert.ToInt32(model.AttrBusConfSelectedStatus) : (int?)null;
            ConfBData.GroupID = model.AttrBusConfGroupID;
            ConfBData.VendorID = model.AttrBusConfVendorID;
            ConfBData.Note = model.AttrBusConfNote;
            ConfBData.VendorType = model.AttrBusVendorType;
            return ConfBData;
        }
        private OperationAmexVendorViewModel InitOperationAmexVendorViewModel(OperationAmexVendorBData data, string ArrivalDate, string OperationTabName, string Category, DateTime? Time)
        {
            var VendorNameTitle = OperationTabName + " Name:";
            if (OperationTabName == "Restaurants")
                VendorNameTitle = "Restaurant Name:";
            if (OperationTabName == "Attractions")
                VendorNameTitle = "Attraction Name:";
            if (OperationTabName == "Guide")
                VendorNameTitle = "Guide:";
            OperationAmexVendorViewModel AmexVendorViewModel = new OperationAmexVendorViewModel
            {
                AmexVendorID=data.AmexVendorID,
                VendorID = data.VendorID !=null ? Convert.ToInt32(data.VendorID) : 0,
                GroupID = data.GroupID != null ? Convert.ToInt32(data.GroupID) : 0,
                LineNo = data.LineNo != null ? Convert.ToInt32(data.LineNo) : 0,
                CardID = data.CardID != null ? Convert.ToInt32(data.CardID) : 0,
                CompanyPhone = data.CompanyPhone != null ? data.CompanyPhone : " ",
                CompanyFax = data.CompanyFax != null ? data.CompanyFax : " ",
                SelectedCurrency = data.SelectedCurrency == "CAD" ? 2 : 1,
                Attention = data.Attention,
                OperationTabName = OperationTabName,
                AmexRestCategory = data.Category == null ? Category : data.Category,
                OperAmexVndArrivalDate = Convert.ToDateTime(ArrivalDate),
                OperAmexVndTime = Time,
                CompanyAddress = data.CompanyAddress != null ? data.CompanyAddress : " ",
                VendorNameTitle = VendorNameTitle,
                VendorName = data.VendorName != null ? data.VendorName : " ",
                GroupCode = data.GroupCode != null ? data.GroupCode : " ",
                GroupName = data.GroupName != null ? data.GroupName : " ",
                Charged = data.Charged != null ?  Convert.ToBoolean(data.Charged) : false,
                IsItCommissionable = data.IsItCommissionable != null ? Convert.ToBoolean(data.IsItCommissionable) : false,
                Date = data.Date != null ? Convert.ToDateTime(data.Date).ToString("dd/MMM/yy") : "",
                CommissionReceivedDate = data.CommissionReceivedDate != null ? Convert.ToDateTime(data.CommissionReceivedDate).ToString("dd/MMM/yy") : "",
                AuthorizedAmount = data.AuthorizedAmount != null ? Convert.ToDecimal(data.AuthorizedAmount).ToString("F") : "0",
                CommissionAmountReceived = data.CommissionAmountReceived != null ? Convert.ToDecimal(data.CommissionAmountReceived).ToString("F") : "0",
                CommissionableAmount = data.CommissionableAmount != null ? Convert.ToDecimal(data.CommissionableAmount).ToString("F") : "0",
                ExpectedCommissionAmount = data.ExpectedCommissionAmount != null ? Convert.ToDecimal(data.ExpectedCommissionAmount).ToString("F") : "0",
                PaymentFor = data.PaymentFor,
                PreparedBy = data.PreparedBy,
                CardType=data.CardType,
                PlaceHolderName=data.PlaceHolderName,
                CardNumber=data.CardNumber,
                CardValidToDate = data.CardValidToDate != null ? "EXP. DATE  " + Convert.ToDateTime(data.CardValidToDate).ToString("MM/yyy") : "",
            };
            AmexVendorViewModel.Currency = new List<System.Web.WebPages.Html.SelectListItem>();
            foreach (var Curr in data.Currency)
                AmexVendorViewModel.Currency.Add(new System.Web.WebPages.Html.SelectListItem() { Text = Curr.Value, Value = Curr.Key.ToString() });
            return AmexVendorViewModel;
        }
        private OperationAmexVendorBData InitOperationAmexVendorBD(OperationAmexVendorViewModel model)
        {
            OperationAmexVendorBData AmexVendorBD = new OperationAmexVendorBData
            {
                AmexVendorID = model.AmexVendorID,
                VendorID = model.VendorID,
                GroupID = model.GroupID,
                LineNo = model.LineNo,
                CardID = model.CardID,
                OperationTabName = model.OperationTabName,
                ArrivalDate = model.OperAmexVndArrivalDate,
                Time = model.OperAmexVndTime,
                SelectedCurrency = model.SelectedCurrency == 2 ? "CAD" : "USD",
                Attention = model.Attention,
                Charged = model.Charged,
                Category = model.AmexRestCategory,
                IsItCommissionable = model.IsItCommissionable,
                Date = model.Date != null ? Convert.ToDateTime(model.Date): (DateTime?)null,
                CommissionReceivedDate = model.CommissionReceivedDate != null ? Convert.ToDateTime(model.CommissionReceivedDate) : (DateTime?)null,
                AuthorizedAmount = model.AuthorizedAmount != null ? Convert.ToDecimal(model.AuthorizedAmount): (decimal?)null,
                CommissionAmountReceived = model.CommissionAmountReceived != null ? Convert.ToDecimal(model.CommissionAmountReceived) : (decimal?)null,
                CommissionableAmount = model.CommissionableAmount != null ? Convert.ToDecimal(model.CommissionableAmount) : (decimal?)null,
                ExpectedCommissionAmount = model.ExpectedCommissionAmount != null ? Convert.ToDecimal(model.ExpectedCommissionAmount) : (decimal?)null,
                PaymentFor = model.PaymentFor,
                PreparedBy = model.PreparedBy,
            };
            return AmexVendorBD;
        }
        private bool CreateFolderIfNeeded(string path)
        {
            bool result = true;
            if (!Directory.Exists(path))
            {
                try
                {
                    Directory.CreateDirectory(path);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToMessageAndCompleteStacktrace());
                    result = false;
                }
            }
            else
            {
                try
                {
                    DirectoryInfo dir = new DirectoryInfo(path);

                    foreach (FileInfo fi in dir.GetFiles())
                    {
                        fi.IsReadOnly = false;
                        fi.Delete();
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToMessageAndCompleteStacktrace());
                    result = false;
                }
            }
            return result;
        }
        private string DoubleStringGeneratorF(double? Sum)
        {
            return Sum < 0 ? "(" + Convert.ToDouble(Sum * -1).ToString("C2") + ")"
                   : Convert.ToDouble(Sum).ToString("C2");
        }
        #endregion
    }
}